Lecture 2
A Simple 2D Graphics Language
Our Goal
2D Graphics
One extra bit of magic…
#lang 2htdp/isl+
(require 2htdp/image)
Rectangles and Squares
(rectangle width height� mode color)
(square width mode color)
Creates a rectangle where…
Circles and Ellipses
(ellipse width height� mode color)
(circle radius mode color)
Creates curved objects where…
Compositing images
(overlay image image …)
(underlay image image …)
Make a compound image from multiple image objects where…
Official Documentation Link (overlay)
Official Documentation Link (underlay)
Placing images next to one another
(above images …)
(beside images …)
Both make an image by laying out the specified images vertically (above) or horizontally (beside).
Shifting images relative to one another
(overlay/offset top-image
right down
bottom-image)
Composites the two images according to some rules:
overlay/xy works similarly
Rotate
(rotate angle image)
Rotates image counter-clockwise angle degrees about its center
Wedges
(wedge radius angle mode color)
Creates a wedge of a circle with…
Scaling
(scale scale-factor image)
Scale an inputted image by some scale-factor
Ex. 10 means 10 times as large
A note on Colors
Color objects
(make-color r g b)
(make-color r g b a)
(color r g b)
Alternatively, you can also specify a color using a color object
Using define to "remember" data
(define a-green-square (square 10 "solid" "green"))
Debugging Example
Dataflow debugging example
(overlay (circle 30 "solid" "green" square 100 "solid" "orange")))
Checking the data flow
Dataflow debugging example
circle: expects only 3 arguments, but found 7
(overlay (circle 30 "solid" "green" square 100 "solid" "orange")))
Dataflow debugging example
(overlay (circle 30 "solid" "green" square 100 "solid" "orange"))
(overlay (circle 30� "solid"� "green"
square� 100
"solid" � "orange")))
Dataflow debugging example
(overlay (circle 30� "solid"� "green"
(square 100
"solid" � "orange")))
Dataflow debugging example
(overlay (circle 30� "solid"� "green"
(square 100
"solid" � "orange")))
Dataflow debugging example
(overlay (circle 30� "solid"� "green"))
(overlay (circle 30� "solid"� "green")
(square 100
"solid" � "orange"))