Browse Source

Finish 2.50

master
parent
commit
964908be26
  1. 45
      2.50.scm
  2. 23
      imagelib.scm

45
2.50.scm

@ -0,0 +1,45 @@
(load "displaylib.scm")
(load "imagelib.scm")
(title "Exercise 2.50")
(doc "Define the transformation flip-horiz, which flips painters horizontally, and transformations that rotate painters counterclockwise by 180 degrees and 270 degrees.")
; Exercise start
; -- define transform-painter --
(define (transform-painter painter origin corner1 corner2)
(lambda (frame)
(let ((m (frame-coord-map frame)))
(let ((new-origin (m origin)))
(painter
(make-frame new-origin
(sub-vect (m corner1) new-origin)
(sub-vect (m corner2) new-origin)))))))
(define (flip-horiz painter)
(transform-painter painter
(make-vect 1.0 0.0) ; new origin
(make-vect 0.0 0.0) ; new end of edge1
(make-vect 1.0 1.0))) ; new end of edge2
(define (rot-180 painter)
(transform-painter painter
(make-vect 1.0 1.0)
(make-vect 0.0 1.0)
(make-vect 1.0 0.0)))
(define (rot-270 painter)
(transform-painter painter
(make-vect 0.0 1.0)
(make-vect 0.0 0.0)
(make-vect 1.0 1.0)))
; I won't do the wave painter, I have no data
(define frame (make-frame origin (scale-vect 2 xunit) yunit))
(print "-- X frame --")
(draw-X frame)
(print "-- flip-horz frame --")
((flip-horiz draw-X) frame)
(print "-- rot-180 frame --")
((rot-180 draw-X) frame)
(print "-- rot-270 frame --")
((rot-270 draw-X) frame)

23
imagelib.scm

@ -56,3 +56,26 @@
((frame-coord-map frame) (start-segment segment))
((frame-coord-map frame) (end-segment segment))))
segment-list)))
; -- 2.49 -- some painters
(define (outline-frame f)
((segments->painter
(list (make-segment origin yunit)
(make-segment yunit one-one)
(make-segment one-one xunit)
(make-segment xunit origin))) f))
(define (draw-X f)
((segments->painter
(list (make-segment origin one-one)
(make-segment xunit yunit))) f))
(define (mid-point A B) (scale-vect .5 (add-vect A B)))
(define (diamond f)
((segments->painter
(list
(make-segment (make-vect .5 0) (make-vect 1 .5))
(make-segment (make-vect 1 .5) (make-vect .5 1))
(make-segment (make-vect .5 1) (make-vect 0 .5))
(make-segment (make-vect 0 .5) (make-vect .5 0)))) f))

Loading…
Cancel
Save