SICP Exercise 2.52
Question
Make changes to the square limit of wave
shown in Figure 2.9 by working at
each of the levels described above. In particular:
- Add some segments to the primitive
wave
painter of Exercise 2.49 (to add a smile, for example). - Change the pattern constructed by
corner-split
(for example, by using only one copy of theup-split
andright-split
images instead of two). - Modify the version of
square-limit
that usessquare-of-four
so as to assemble the corners in a different pattern. (For example, you might make the big Mr. Rogers look outward from each corner of the square.)
Answer
Let us step through this one by one. This was a little random, but I added a
smiley face to the wave
painter:
(define wave-segments
(list
(make-segment
(make-vect 0.006 0.840) (make-vect 0.155 0.591))
(make-segment
(make-vect 0.006 0.635) (make-vect 0.155 0.392))
(make-segment
(make-vect 0.304 0.646) (make-vect 0.155 0.591))
(make-segment
(make-vect 0.298 0.591) (make-vect 0.155 0.392))
(make-segment
(make-vect 0.304 0.646) (make-vect 0.403 0.646))
(make-segment
(make-vect 0.298 0.591) (make-vect 0.354 0.492))
(make-segment
(make-vect 0.403 0.646) (make-vect 0.348 0.845))
(make-segment
(make-vect 0.354 0.492) (make-vect 0.249 0.000))
(make-segment
(make-vect 0.403 0.000) (make-vect 0.502 0.293))
(make-segment
(make-vect 0.502 0.293) (make-vect 0.602 0.000))
(make-segment
(make-vect 0.348 0.845) (make-vect 0.403 0.999))
(make-segment
(make-vect 0.602 0.999) (make-vect 0.652 0.845))
(make-segment
(make-vect 0.652 0.845) (make-vect 0.602 0.646))
(make-segment
(make-vect 0.602 0.646) (make-vect 0.751 0.646))
(make-segment
(make-vect 0.751 0.646) (make-vect 0.999 0.343))
(make-segment
(make-vect 0.751 0.000) (make-vect 0.597 0.442))
(make-segment
(make-vect 0.597 0.442) (make-vect 0.999 0.144))
(make-segment
(make-vect 0.45 0.78) (make-vect 0.5 0.75))
(make-segment
(make-vect 0.5 0.75) (make-vect 0.55 0.78))
(make-segment
(make-vect 0.5 0.87) (make-vect 0.5 0.82))
(make-segment
(make-vect 0.5 0.82) (make-vect 0.52 0.82))
(make-segment
(make-vect 0.43 0.89) (make-vect 0.45 0.91))
(make-segment
(make-vect 0.45 0.91) (make-vect 0.47 0.89))
(make-segment
(make-vect 0.53 0.89) (make-vect 0.55 0.91))
(make-segment
(make-vect 0.55 0.91) (make-vect 0.57 0.89))))
(define wave (segments->painter wave-segments))
This is what it looks like now:
Next, I modified corner-split
so that the wave
figures are holding hands.
(define (corner-split-1 p n)
(if (= n 0)
p
(beside (below p (up-split (rotate180 p) (- n 1)))
(below (right-split (flip-horiz p) (- n 1))
(corner-split (flip-vert p) (- n 1))))))
It now looks like this with an n
of 1
:
For our modified square-limit
procedure, your fantasy is the only limit. I
just tried to make something that looks cool.
(define (square-limit-1 painter n)
(let ((combine4
(square-of-four flip-vert
rotate180
identity
flip-horiz)))
(combine4 (corner-split painter n))))
This is what it looks like with an n
of 2
: