Sunday, 4 November 2012

How Could Centre a Model in an Animation?


     The Exercise 8.3.2 asks to modify Exercise 8.3.1 so that the circle appears centered and unmoving in a 200 x 200 white background, so it appears to grow around a fixed center. Initially, I was confused by the method used in Exercise 8.2.3- place-image. But then I was stuck, because the circle is growing, I couldn’t find the exact distance from the left and top-edge for the circle. So, I checked the previous notes, and found a function called overlay, which can put two images together, and let the first image be on the center of the second image. Then I wrote the solution for this exercise:

(check-expect (blue-circle-of-size-center 2)

                      (overlay(circle 2 “solid””blue”)(rectangle 200 200 “solid””white”)))

(check-expect (blue-circle-of-size-center 37)

                      (overlay(circle 37 “solid””blue”)(rectangle 200 200 “solid””white”)))

 

(define(blue-circle-of-size-center radius)

                      (overlay(circle radius “solid””blue”)(rectangle 200 200 “solid””white”)))

 

(big-bang 7 (check-with number?) (on-draw blue-circle-of-size-center) (on-tick add1 1/2))

No comments:

Post a Comment