sicp-ex-2.49


 ;; Exercise 2.49 
 (let ((tl (make-vect 0 1)) 
       (tr (make-vect 1 1)) 
       (bl (make-vect 0 0)) 
       (br (make-vect 1 0))) 
   ;; a 
   (segments->painter (list 
                       (make-segment bl tl) 
                       (make-segment tl tr) 
                       (make-segment tr br) 
                       (make-segment br bl))) 
   ;; b 
   (segments->painter (list 
                       (make-segment bl tr) 
                       (make-segment br tl)))) 
    
 (let ((l (make-vect 0 0.5)) 
       (t (make-vect 0.5 1)) 
       (r (make-vect 1 0.5)) 
       (b (make-vect 0.5 0))) 
   ;; c 
   (segments->painter (list 
                       (make-segment l t) 
                       (make-segment t r) 
                       (make-segment r b) 
                       (make-segment b l)))) 

<< Previous exercise (2.48) | Index | Next exercise (2.50) >>


caesarjuly

I think my solution is more accurate

  
 (define (base frame) (origin frame)) 
 (define (right frame) (add-vector (base frame) (edge1 frame))) 
 (define (left frame) (add-vector (base frame) (edge2 frame))) 
 (define (top frame) (add-vector (right frame) (edge2 frame))) 
  
 (define (frame-painter frame)  
     (let ((b (make-segment (base frame) (right frame))) 
           (l (make-segment (base frame) (left-frame))) 
           (t (make-segment (left-frame) (top-frame))) 
           (r (make-segment (right-frame) (top-frame)))) 
         ((segments->painter (list b l t r)) frame))) 
  
 (define (x-painter frame)  
     (let ((h (make-segment (left frame) (right frame))) 
           (v (make-segment (base frame) (top-frame)))) 
         ((segments->painter (list h v)) frame))) 
  
 (define (middle-painter frame)  
     (let ((b (/ (add-vector (base frame) (right frame)) 2)) 
           (l (/ (add-vector (base frame) (left frame)) 2)) 
           (t (/ (add-vector (left frame) (top frame)) 2)) 
           (r (/ (add-vector (right frame) (top frame)) 2))) 
         ((segments->painter (list (make-segment b r)  
                                   (make-segment b l) 
                                   (make-segment l t) 
                                   (make-segment r t)))  
         frame))) 

brave one

  
  
  
 ; sorry no make-<something> and selectors here, too much to type! 
  
 ; a. 
 (define outline 
   (let ((segments '( 
                     ((0 0) (0 1)) 
                     ((0 1) (1 1)) 
                     ((1 1) (1 0)) 
                     ((1 0) (0 0)) 
                    ))) 
     (segments->painter segments))) 
  
 ; b. 
 (define cross 
   (let ((segments '( 
                     ((0 0) (1 1)) 
                     ((0 1) (1 0)) 
                    ))) 
     (segments->painter segments))) 
  
 ; c. 
 (define diamond 
   (let ((segments '( 
                     ((0 0.5) (0.5 1)) 
                     ((0.5 1) (1 0.5)) 
                     ((1 0.5) (0.5 0)) 
                     ((0.5 0) (0 0.5)) 
                    ))) 
     (segments->painter segments)))