Instantly share code, notes, and snippets.

What would you like to do?
A Penrose tiling is a non-periodic tiling generated by an aperiodic set of prototiles. Penrose tilings are named after mathematician and physicist Roger Penrose who investigated these sets in the 1970s. This gist describes the tiling in terms of a rewriting grammar (an 'L-system') and renders using a turtle ( on…
(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]
[P b Q R R P b Q R R P b Q R R P b Q R R P b Q]
[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)
; (sel1 :svg#world)
; (draw! ->svg (nth penrose-tiling-seq 5) [800 600]))
(show canvas)
(->canvas ctx)
(nth penrose-tiling-seq 5) [800 600])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment