; ======================================================================
;
; Structure and Interpretation of Computer Programs
; (trial answer to excercises)
;
; 计算机程序的构造和解释(习题试解)
;
; created: code17 08/20/05
; modified:
; (保持内容完整不变前提下,可以任意转载)
; ======================================================================
;; SICP No.2.52
;; a
(define wave
(let ((p01 (make-vect 0.40 1.00)) (p02 (make-vect 0.60 1.00))
(p03 (make-vect 0.00 0.80)) (p04 (make-vect 0.35 0.80))
(p05 (make-vect 0.65 0.80)) (p06 (make-vect 0.00 0.60))
(p07 (make-vect 0.30 0.60)) (p08 (make-vect 0.40 0.60))
(p09 (make-vect 0.60 0.60)) (p10 (make-vect 0.70 0.60))
(p11 (make-vect 0.20 0.55)) (p12 (make-vect 0.30 0.55))
(p13 (make-vect 0.35 0.50)) (p14 (make-vect 0.65 0.50))
(p15 (make-vect 0.20 0.45)) (p16 (make-vect 1.00 0.40))
(p17 (make-vect 0.50 0.20)) (p18 (make-vect 1.00 0.20))
(p19 (make-vect 0.25 0.00)) (p20 (make-vect 0.40 0.00))
(p21 (make-vect 0.60 0.00)) (p22 (make-vect 0.75 0.00))
(p23 (make-vect 0.40 0.75)) (p24 (make-vect 0.60 0.75))
(p25 (make-vect 0.50 0.70)))
(let ((wave-outline
(list (make-segment p01 p04) (make-segment p04 p08)
(make-segment p07 p11) (make-segment p08 p07)
(make-segment p11 p03) (make-segment p06 p15)
(make-segment p15 p12) (make-segment p12 p13)
(make-segment p13 p19) (make-segment p20 p17)
(make-segment p17 p21) (make-segment p22 p14)
(make-segment p14 p18) (make-segment p16 p10)
(make-segment p10 p09) (make-segment p09 p05)
(make-segment p05 p02) (make-segment p25 p23)
(make-segment p25 p24))))
(segments->painter wave-outline))))
;; b
(define (conner-split painter n)
(let ((up (up-split painter (- n 1)))
(right (right-split painter (- n 1)))
(corner (corner-split painter (- n 1))))
(beside (below painter up)
(below right corner))))
;; c
(define (square-limit painter n)
(let ((combine4 (square-of-four identity flip-horiz
flip-vert rotate180)))
(combine4 (corner-split painter n))))