Created
November 21, 2022 15:25
-
-
Save jdh30/b1c9822aaeb110e4806cbcc958c53349 to your computer and use it in GitHub Desktop.
Pythagoras' Tree
This file contains 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
let branches m = | |
{ { Vec2.rotate(π/2 - asin(4/5)); | |
Vec2.scale(4/5, 4/5); | |
Vec2.translate(0, -1) }; | |
{ Vec2.translate(1, -1); | |
Vec2.rotate(-π/2 + asin(3/5)); | |
Vec2.scale(3/5, 3/5); | |
Vec2.translate(1/3, 0) } } | |
@ Array.map [m2 → Array.concat{m; m2}] | |
let square = | |
{0,0; 1,0; 1,1; 0,1} | |
@ Array.map Line | |
@ Closed | |
let shape color m = | |
let style = Style(Fill color, NoStroke) in | |
Shape(style, Path(Contour.transform m square)) | |
let trunks color ms = Array.map (shape color) ms | |
let burlyWood = Hex "deb887" | |
let rec tree n ms = | |
if n=0 then {trunks Green ms} else | |
let ms2 = Array.collect branches ms in | |
Array.concat{{trunks burlyWood ms}; tree (n-1) ms2} | |
let () = | |
tree 8 {{Vec2.translate (300, 300); Vec2.scale (100, 100)}} | |
@ Array.concat | |
@ Html.ofSvg (600, 600) | |
@ yield |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment