120 likes | 133 Views
Programming with Images (continued). Another teachpack – “tiles.ss”. Download from the website: “http://www.adelphi.edu/sbloch/class/171/tiles.plt Save to the folder: “C:ProgramFilesPLTTeachpack” Open DrScheme. Go to Add Teachpack. Right click on file, then click open.
E N D
Programming with Images (continued)
Another teachpack – “tiles.ss” • Download from the website: “http://www.adelphi.edu/sbloch/class/171/tiles.plt • Save to the folder: “C:\ProgramFiles\PLT\Teachpack” • Open DrScheme. Go to Add Teachpack. • Right click on file, then click open. • These creates a second file. Install it. • Press Run and Let’s Have Fun!
Exercise 4: Using “tiles.ss” • Make sure that “world.ss” is installed. • Download and install “tiles.ss” on your computer. Press “Run”. • Put the rectangle (from last class) next to the circle. • Find the hands picture on your computer in “My Pictures”. Define it as a variable. • Reflect the hands picture horizontally. • Reflect the hands picture vertically.
Writing our own function… ; Purpose: To create the horizontal mirror image of any picture. ; Contract: image -> image
Writing our own function… ; Purpose: To create the horizontal mirror image of any picture. ; Contract: image -> image “Examples of mirror-horiz:” (define ADAM ) (mirror-horiz ADAM) “should be” (image-beside Adam (reflect-horiz ADAM))
Writing our own function… ; Purpose: To create the horizontal mirror image of any picture. ; Contract: image -> image (define (mirror-horiz pic) (… pic …) ) “Examples of mirror-horiz:” (define ADAM ) (mirror-horiz ADAM) “should be” (image-beside ADAM (reflect-horiz ADAM))
Writing our own function… ; Purpose: To create the horizontal mirror image of any picture. ; Contract: image -> image (define (mirror-horiz pic) (image-beside pic (reflect-horiz pic))) “Examples of mirror-horiz:” (mirror-horiz ADAM) “should be” (image-beside ADAM (reflect-horiz ADAM))
Exercise 5: counterchange Define a function called counterchange that takes in two images and returns a 2x2 arrangement of them as shown here.
Solution: counterchange ; Purpose: To create a small checkerboard pattern with any ; two images. ; Contract: image image -> image ; Examples: ;(counterchange (rectangle 50 30 ‘solid ‘blue) (rectangle 20 ;20 ‘solid ‘red)) “should be” “a blue rectangle next to a red ;square with a red square next to a blue rectangle below it” ;(counterchange (circle 30 ‘solid ‘green) hands) “should be” ;“a green circle next to the hands with the hands next to a ;green circle below it”
Solution: counterchange ; Skeleton: ; (define (counterchange pic1 pic2) ; ( … pic1 … pic2 …)) ;Informal Thinking ;We need to put two images next to each other. How do we do this? ;How do we put an image directly above another?
Solution: counterchange ; Function: (define (counterchange pic1 pic2) (image-above (image-beside pic1 pic2) (image-beside pic2 pic1) ) )
Last five weeks… • Programs that deal with Conditions • Working with Compound Data • The final!