(define pi (acos -1)) (define rad->deg (lambda (rad) (* rad (/ 360 (* 2 pi))))) (define deg->rad (lambda (deg) (* deg (/ (* 2 pi) 360)))) (define ellipse (lambda (r) (ellipse-helper r 360))) (define ellipse-helper (lambda (r t) (if (= t 0) (adjoin) (adjoin (straight 1) (bend (- (rad->deg (atan (cos (deg->rad t)) (* (- r) (sin (deg->rad t))))) (rad->deg (atan (cos (deg->rad (sub1 t))) (* (- r) (sin (deg->rad (sub1 t)))))))) (ellipse-helper r (sub1 t))))))
(define tree-step (lambda (trunk left-branch right-branch) (adorn trunk (adjoin (bend -20) left-branch) (adjoin (bend 20) right-branch))))If you want to make your trees as nice looking as possible, you will probably have to decrease the trunk length and branch angle as the recursion depth increases. To do this, it is useful to know the maximum depth of the s-expression prior to building the graphic object depicting its cons-tree.
The Monkey Tree (The Fractal Geometry of Nature, p. 31)
(define d (/ (sqrt 3) 3)) (define monkey-step (lambda (side rside) (adjoin (bend -60) (mirror side) (mirror rside) (bend 60) side (bend 60) (mirror rside) (bend 150) (scale-size d (mirror rside)) (scale-size d (mirror side)) (bend -60) (scale-size d rside) (bend -60) (scale-size d rside) (scale-size d side) (bend -90) rside side))) (define rmonkey-step (lambda (side rside) (adjoin rside side (bend 90) (scale-size d rside) (scale-size d side) (bend 60) (scale-size d side) (bend 60) (scale-size d (mirror rside)) (scale-size d (mirror side)) (bend -150) (mirror side) (bend -60) rside (bend -60) (mirror side) (mirror rside) (bend 60)))) (define monkey-tree (lambda (n len) (if (= n 0) (straight len) (monkey-step (monkey-tree (sub1 n) len) (rmonkey-tree (sub1 n) len))))) (define rmonkey-tree (lambda (n len) (if (= n 0) (straight len) (rmonkey-step (monkey-tree (sub1 n) len) (rmonkey-tree (sub1 n) len)))))The Koch Snowflake (The Fractal Geometry of Nature, p. 43)
(define koch-step (lambda (side angle) (adjoin side (bend (- angle)) side (bend (* 2 angle)) side (bend (- angle)) side))) (define koch (lambda (n len angle) (if (= n 0) (straight len) (koch-step (koch (- n 1) len angle) angle))))
* This webpage is located at http://cs.unm.edu/~williams/cs257/project1.html