Wednesday, November 21, 2012

Week 11 Joural

In today's lecture, professor used DrrRacket to make snowflake and some other fun patterns.
Today's course is all about recursion.

Here is a function, koch is make the one thrid of a snowflake
(define (koch d)
  (cond
    [(zero? d) (line 5 0 "blue")]
    [else
     (beside/align
      "bottom"
      (koch (sub1 d))
      (rotate 60 (koch (sub1 d)))
      (rotate -60 (koch (sub1 d)))
      (koch (sub1 d)))])

The result for (koch 0) is
_

The result for (koch 1) is
_/\_
Moreover, professor showed us another program, caleld "koch-snowflake
(define (koch-snowflake d)
  (above
   (beside
    (rotate 60 (koch d))
    (rotate -60 (koch d)))
   (rotate 180 (koch d))))

The result of this progam will form a complete snowflake by putting three "koches" (three 1/3 of a snowflake) together like a triangle.

No comments:

Post a Comment