Last active
October 14, 2020 03:36
-
-
Save youz/05e081611b0c1d9c79e3766d754f285a to your computer and use it in GitHub Desktop.
Penrose tiling in SATySFi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @require: standalone | |
| @require: gr | |
| @require: list | |
| let color-k = RGB(0.1, 0.2, 0.6) | |
| let color-a = RGB(0.9, 1.0, 0.7) | |
| let color-b = RGB(0.5, 0.7, 1.0) | |
| % let color-k = RGB(0.0, 0.0, 0.0) | |
| % let color-a = RGB(0.0, 0.0, 0.0) | |
| % let color-b = RGB(0.3, 0.9, 0.6) | |
| let linewidth = 0.05pt | |
| let pi = acos (0. -. 1.) | |
| let invphi = 2.0 /. (exp (log 5.0 /. 2.0) +. 1.0) | |
| let div (x1, y1) (x2, y2) t = | |
| let cx = x1 *' (1. -. t) +' x2 *' t in | |
| let cy = y1 *' (1. -. t) +' y2 *' t in | |
| (cx, cy) | |
| % ref. https://tartarus.org/~simon/20110412-penrose/penrose.xhtml | |
| type tt = A | B | |
| type triangle = tt * point * point * point | |
| let subdivide (t, p, q, r) = | |
| let u = div p q invphi in | |
| let v = div p r invphi in | |
| match t with | |
| | A -> [(B, r, u, p); (A, r, u, q)] | |
| | B -> [(B, v, u, p); (A, v, u, q); (B, r, v, q)] | |
| let-rec gen | |
| | 0 ps = ps | |
| | n ps = List.map subdivide ps |> List.concat |> gen (n - 1) | |
| let draw-triangle transf (t, a, b, c) = | |
| let p = Gr.polygon a [b; c] |> transf in | |
| let c = match t with A -> color-a | B -> color-b in | |
| [fill c p; stroke linewidth color-k p] | |
| let-inline ctx \penrose-tiling size n = | |
| let ox = size *' 0.5 in | |
| let t = ox *' (tan (pi /. 5.0)) in | |
| let p = (0pt, 0pt) in | |
| let r = (size, 0pt) in | |
| let t0 = [(B, p, (ox, t), r); (B, p, (ox, 0pt -' t), r)] in | |
| let transf = Gr.rotate-path (0pt, 0pt) 36.0 in | |
| let gs = gen n t0 | |
| |> List.map (draw-triangle transf) | |
| |> List.concat in | |
| inline-graphics size size 0pt (fun o -> List.map (shift-graphics o) gs) | |
| let-block ctx +test size n = | |
| let-rec f i acc = | |
| if i == n then acc | |
| else | |
| let ib = (read-inline ctx { \penrose-tiling(size)(i); }) ++ inline-fil in | |
| let bb = acc +++ (form-paragraph ctx ib) +++ clear-page in | |
| f (i + 1) bb | |
| in | |
| f 0 block-nil | |
| in | |
| standalone '< | |
| % +p{ \penrose-tiling(400pt)(8); } | |
| +test(400pt)(8); | |
| > |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment