penrose-tiling.cljs
(ns lindenmayer-systems.demo
(:use [turtle.core :only [draw!]]
[turtle.renderer.vector :only [->svg]]
[turtle.renderer.canvas :only [->canvas]]
[enchilada :only [ctx canvas svg]]
[dommy.core :only [set-html! insert-after! replace! hide! show!]]
[jayq.core :only [show]])
(:use-macros [dommy.macros :only [sel1]]))
(def L '(:left 36))
(def R '(:right 36))
(def F '(:fwd 60))
(def P :save)
(def Q :restore)
(def penrose-tiling-seq
(letfn [(seq0 [a b c d e]
(lazy-seq
(cons
[P b Q R R P b Q R R P b Q R R P b Q R R P b Q]
(seq0
[c e R R d e L L L L b e P L c e L L L L a e Q R R]
[R c e L L d e P L L L a e L L b e Q R]
[L a e R R b e P R R R c e R R d e Q L]
[L L c e R R R R a e P R d e R R R R b e Q L L b e]
[]))))]
(seq0 [F] [F] [F] [F] [])))
;(show svg)
;
;(replace!
; (sel1 :svg#world)
; (draw! ->svg (nth penrose-tiling-seq 5) [800 600]))
(show canvas)
(draw!
(->canvas ctx)
(nth penrose-tiling-seq 5) [800 600])