The rkt. files spiral and koch are about doing the same thing.
For koch, it is a function to make the 1/3 of a snowflake.
Here's the function,
(define (koch d)These are two of the outcomes,
(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)))]))
(koch 0)As d=0, when (zero? 0), a blue line (5) shows up.
_
(koch 1)As d=1, it goes to [else ...], when it goes to (koch (sub1 1)), it goes back to (koch 0), which is a blue line.
_/\_
After "koch", it's followed by "koch-snowflake"
Here's the function,
(define (koch-snowflake d)
(above
(beside
(rotate 60 (koch d))
(rotate -60 (koch d)))
(rotate 180 (koch d))))
It forms a complete snowflake by putting three "koches" (three 1/3 of a snowflake) together like a triangle.
It is fun when I trying to imagine the output by myself before checking it with DrRacket.
No comments:
Post a Comment