sicp-ex-2.50



<< Previous exercise (2.49) | Index | Next exercise (2.51) >>


dudrenov

 ;; That's one way of doing it. 
  
  
  
 (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))) 
  
 (define (repeated fn t) 
   (if (= t 1) 
       fn 
       (lambda (x) 
         (fn ((repeated fn (- t 1)) 
              x))))) 
  
 (define (rotate180 painter) 
   ((repeated  rotate90 2) painter)) 
  
 (define (rotate270 painter) 
   ((repeated rotate90 3) painter)) 

charlesdalton

 ;; The other way of doing it ;) 
  
 (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))) 
  
 (define (rotate180 painter) 
   (transform-painter painter 
                      (make-vect 1.0 1.0) 
                      (make-vect 0.0 1.0) 
                      (make-vect 1.0 0.0))) 
  
 (define (rotate270 painter) 
   (transform-painter painter 
                      (make-vect 0.0 1.0) 
                      (make-vect 0.0 0.0) 
                      (make-vect 1.0 1.0))) 

ceasarxinsanium

Here is lazy method of doing it

 (define (rotate180 painter) 
   (rotate90 (rotate90 painter))) 
  
  
 (define (rotate270 painter) 
   (rotate90 (rotate90 (rotate90 painter))))