2012年12月5日星期三

Two probelms solved in Chapter 8 of the book

I found difficulties in solving Exercise 8.3.4 and 8.3.5 and I asked for help. Here is my feedback:
Exercises 8.3.4: Develop an animation of a square, initially 1x1,which grows by 1 pixel in each dimension at each clock tick,centered in a 200x200 window.
Soultion:
(check-expect (growing-square 5)(overlay (rectangle 5 5 "solid" "red")
                                                    (rectangle 200 200 "solid" "white")))
(define (growing-square x)(overlay (rectangle x x "solid" "red")
                                                     (rectangle 200 200 "solid" "white")))
; (big-bang 1 (check-with number ?)(on-draw growing-square)
                                                       (on-tick add 1 1))


Exercise 8.3.5: Develop an animation of a rectangle, initially 2x1, which grows by 1 pixel in height and 2 in width at each clock tick, centered in a 200x200 window.
Solution:
(check-expect (growing-rectangle 5)(overlay (rectangle(* 5 2) 5 "solid" "red")
                                                    (rectangle 200 200 "solid" "white")))
(define (growing-rectangle x)(overlay (rectangle (* x 2) x "solid" "red")
                                                     (rectangle 200 200 "solid" "white")))
; (big-bang 1 (check-with number ?)(on-draw growing-rectangle)
                                                       (on-tick add 1 1/2))

没有评论:

发表评论