Monday, 30 January 2012

SICP Graphics



polygon,sides and length of polygon,structure of polygon


Write a procedure that takes two arguments sides,length and

representing the number of sides of polygon
and length of each side.


(require graphics/turtles)
(turtles)
(define (drawpoly sides length)
  (define (helper angle length count)
    (if (equal? (- sides 1) count)
        (begin
        (draw length)
        (turn angle))
        (begin
          (draw length)
          (turn angle)
           (helper angle length (+ count 1)))))
        (helper (/ 360 sides) length 0))




circle,radius of a circle,circle,structure of a circle


Write a procedure that takes two arguments radius of a circle and

number of sides of approximating polygon.



(define (drawcircle radius sides)
  (define (helper angle radius count)
    (if (equal? (- sides 1) count)
        (begin
          (draw radius)
          (turn angle))
          (begin
            (draw radius)
            (turn angle)
            (helper angle radius (+ count 1)))))
                    (helper (/ 360 sides) (* 2 3.14 radius) 0))





squares,length of the side of square,ratio of the length of square,

diagram of series of square

Write a procedure that takes two arguments length of the side of the first square

and the ratio of the side of each successive square and return the number of square to be
drawn as input.


(define (recursqr level length ratio)
  (if (equal? level 0)
      (drawpoly 4 length)
      (begin
        (drawpoly 4 length)
      (move-offset (+ length) (- length))
      (recursqr (- level 1) (/ length ratio) ratio))))



Keywords:triangle,designing in triangle,multiple series of triangle

Write a procedure to draw a triangle.



(define (s level length)
  (if (= level 0)
      (drawpoly 3 length)
      (begin
        (drawpoly 3 length)
        (move (/ length 2))
              (s (- level 1) (/ length 2))
              (turn 120)
               (s (- level 1) (/ length 2))
               (move (/ length 2))
               (turn 240)
               (s (- level 1) (/ length 2))
               (turn -60)
               (move (/ length 2))
               (turn 60)
               (move (/ length 2))
               (turn 180)
            (draw length)
               (turn 180))))


tree,structure of tree,series of tree,


write a procedure to draw a tree.




(define (tree level length)
  (if (= level 0)
      (begin
        (turn 90)
        (draw length)
        (turn 180)
        (move length)
        (turn 180))
        (begin
          (tree (- level 1) length)
      (draw length)
          (turn -120)
          (tree (- level 1) (* length .7))
          (turn -30)
     (tree (- level 1) (* length .7))
     (turn 150)
     (move length)
     (turn 180))))