(load "snapl.scm") ;; the koch snowflake starts from a triangle (define koch-start triangle) ;; the koch snowflake editing rule has 4 lines each of which ;; are 1/3 long (define koch-program '((mark edge (/ 1 3)) (turn (- angle60)) (mark edge (/ 1 3)) (turn (* 2 angle60)) (mark edge (/ 1 3)) (turn (- angle60)) (mark edge (/ 1 3)))) ;; this version uses cosine explicitly, and relates ;; more closely to the next part (define koch-program '((mark edge (/ 1 3)) (turn (- angle60)) (mark edge (/ (/ 1 6) (cos angle60))) (turn (* 2 angle60)) (mark edge (/ (/ 1 6) (cos angle60))) (turn (- angle60)) (mark edge (/ 1 3)))) (define snowflake (snapl-edit koch-program (snapl-edit koch-program (snapl-run koch-start)))) (snapl-show snowflake) ;; this version uses a switch to only put in some of the triangles ;; using two line labels: a and b (define triangle2 '((turn (- angle60)) (mark b 1) (turn (* 2 angle60)) (mark b 1) (turn (* 2 angle60)) (mark b 1))) (define koch-program2 '((switch (a (mark a 1)) (b (mark a (/ 1 3)) (turn (- angle60)) (mark b (/ 1 3)) (turn (* 2 angle60)) (mark b (/ 1 3)) (turn (- angle60)) (mark a (/ 1 3)))))) (define snowflake2 (snapl-edit koch-program2 (snapl-edit koch-program2 (snapl-edit koch-program2 (snapl-edit koch-program2 (snapl-run triangle2)))))) (snapl-show snowflake2) ;; this is a square (define other-start '((mark edge 1) (turn (/ pi 2)) (mark edge 1) (turn (/ pi 2)) (mark edge 1) (turn (/ pi 2)) (mark edge 1))) ;; this value needed fine-tuning to get things to look right... (define almost90 (/ pi 2.07)) ;; this is the rule for the second fractal design (note that ;; all the angles are negatived from what was in the above) (define other-program '((mark edge 0.475) (turn almost90) (mark edge (/ 0.025 (cos almost90))) (turn (* -2 almost90)) (mark edge (/ 0.025 (cos almost90))) (turn almost90) (mark edge 0.475))) (define otherflake (snapl-edit other-program (snapl-edit other-program (snapl-edit other-program (snapl-run other-start))))) ;(snapl-show otherflake)