Define the transformation flip-horiz
, which flips painters
horizontally, and transformations that rotate painters
counterclockwise by 180 and 270 degrees.
Analogus to flip-vert
define in the text we define flip-horiz
:
(define (flip-horiz painter)
(transform-painter painter
(make-vect 1.0 0.0)
(make-vect 0.0 0.0)
(make-vect 1.0 1.0)))
And 180 and 270 counterclockwise rotations (we repeatedly apply
rotate90
defined in the text):
(define (rotate90 painter)
(transform-painter painter
(make-vect 1.0 0.0)
(make-vect 1.0 1.0)
(make-vect 0.0 0.0)))
(define (rotate180 painter)
(rotate90 (rotate90 painter)))
(define (rotate270 painter)
(rotate90 (rotate180 painter))
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).
Analogous to beside
:
(define (below painter1 painter2)
(let ((split-point (make-vect 0.0 0.5)))
(let ((paint-below
(transform-painter painter1
(make-vect 0.0 0.0)
(make-vect 1.0 0.0)
split-point))
(paint-above
(transform-painter painter2
split-point
(make-vect 0.5 1.0)
(make-vect 0.0 1.0))))
(lambda (frame)
(paint-above frame)
(paint-below frame)))))
Using beside
and rotations:
(define (below painter1 painter2)
(rotate90 (beside (rotate270 painter1)
(rotate270 painter2))))