Created
June 4, 2019 15:24
-
-
Save cormullion/f17783e7271a00242454baf93c6230c8 to your computer and use it in GitHub Desktop.
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
using Luxor, Colors | |
function phyllotaxis(L, startrad, N) | |
deviation = 5/8 | |
goldenangle = mod2pi(Base.MathConstants.φ * 2π) | |
lgrad = 0.45L | |
lgarea = lgrad^2 * π | |
meanarea = lgarea/N | |
minarea = meanarea * (1 - deviation) | |
maxarea = meanarea * (1 + deviation) | |
fudge = 0.87 | |
cumarea = 0.0 | |
for i in 1:N | |
ratio = i/N | |
smarea = minarea + ratio * (maxarea - minarea) | |
smdia = 2sqrt(smarea/π) | |
adjsmdia = smdia * fudge | |
cumarea += smarea | |
spiralrad = startrad + sqrt(cumarea/π) | |
pos = polar(spiralrad, i * goldenangle) | |
circle(pos, adjsmdia/2, :fill) | |
end | |
end | |
function flower(pos; | |
color1=colorant"white", | |
color2=colorant"hotpink4", | |
npetals=5, | |
rad=50) | |
@layer begin | |
translate(pos) | |
petal = box(O, rad, rad/rand(1.5:0.1:2), vertices=true) | |
for i in range(0, step=2π/npetals, length=npetals) | |
@layer begin | |
rotate(i) | |
translate(rad, 0) | |
sethue(color1) | |
drawbezierpath(makebezierpath(petal), :fillpreserve) | |
sethue("grey60") | |
strokepath() | |
end | |
end | |
sethue(color2) | |
drawbezierpath(makebezierpath(star(O, rad, rand(6:18), 0.4, vertices=true)), :fill) | |
sethue("darkmagenta") | |
phyllotaxis(rad/2, rad/10, 200) | |
sethue("orange") | |
phyllotaxis(rad/2, rad/6, 50) | |
end | |
end | |
@svg begin | |
background("azure") | |
setopacity(0.9) | |
[flower(pt, color1=LCHab(120, 80, rand(0:180)), npetals=rand(5:12), rad=rand(25:100)) for pt in randompointarray(BoundingBox()..., 20)] | |
end 800 500 "/tmp/flowers" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment