Saturday, 27 October 2012

Pixels

Opppss.. I forgot to post this. I sent it to my email since I did not have my blogger password available when  I wrote this..
I am having trouble completing exercises 8.33-8.35. Each of these questions deals with two challenges; pixels and movement. I began my search on Google, trying to figure my pixel problem out. My search led me to a very complicated page, which did not further assist me with my queries. So I decided that I was going to make my way to see Professor Heap at 5pm. We worked on 8.35- “develop an animation of a rectangle initially 1 x 2, which grows by 1 pixel in height and 2 pixels in width at each clock tick, centered in a 200 x 200 window.” The hardest part was to figure out how to make the picture grow 1 x 2 pixels. Prof. Heap had an idea to use one placeholder (x) and 2 times that placeholder (2x). So here is what it looks like..
;double-rectangle: number-> image
;draw-rectangle w by 2w centered on 200 x 200

(check-expect (double-rectangle 1
            (overlay
                        (rectangle 1 2 “solid” “yellow”)
                        (rectangle 200  200 “solid” “white”)))

(define (double-rectangle w
            (overlay
                        (rectangle w (* 2w) “solid” “yellow”)
                        (rectangle 200  200 “solid” “white”)))

(big-bang 1
            (on-tick add1)
            (on-draw double rectangle))


Thank you for your help Prof Heap!

No comments:

Post a Comment