1 day ago
my attempt to do the exercises in sicp.
Sunday, July 20, 2008
sicp exercise 2.51
;; Exercise 2.51. Define the below operation for painters. Below takes two painters as arguments. The resulting painter, given a frame, draws with the first painter in the bottom of the frame and with the second painter in the top. Define below in two different ways -- first by writing a procedure that is analogous to the beside procedure given above, and again in terms of beside and suitable rotation operations (from exercise 2.50).
(define (beside painter1 painter2)
(let ((split-point (make-vect 0.5 0.0)))
(let ((paint-left
(transform-painter painter1
(make-vect 0.0 0.0)
split-point
(make-vect 0.0 1.0)))
(paint-right
(transform-painter painter2
split-point
(make-vect 1.0 0.0)
(make-vect 0.5 1.0))))
(lambda (frame)
(paint-left frame)
(paint-right frame)))))
(define (below painter1 painter2)
(let ((split-point (make-vect 0.0 0.5)))
(let ((paint-above
(transform-painter painter1
split-point
(make-vect 0.1 0.5)
(make-vect 0.0 1.0)))
(paint-below
(transform-painter painter2
(make-vect 0.0 0.0)
(make-vect 1.0 0.0)
split-point)))
(lambda (frame)
(paint-above frame)
(paint-below frame)))))
;; below can be expressed in terma of besides as
;; (rotate-270 (besides (rotate-90 painter) (rotate-90 painter)))
(define (below1 painter1 painter2)
(rotate-270-deg-counterclockwise (besides (rotate-90-deg-cc painter1))
(besided (rotate-90-deg-cc painter2))))
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment