Yep, when it's late and I'm too tired to do any useful coding, I surf Rosetta Code and implement a task or two. 🙂 Today it led me to this fun one: the Barnsley fern.
This is a type of fractal created through some mathematical wizardry. I don't claim to really understand how it works, but it does! Here's the code for the MiniScript implementation:
clear
x = 0
y = 0
for i in range(100000)
gfx.setPixel 300 + 58 * x, 58 * y, color.green
roll = rnd * 100
xp = x
if roll < 1 then
x = 0
y = 0.16 * y
else if roll < 86 then
x = 0.85 * x + 0.04 * y
y = -0.04 * xp + 0.85 * y + 1.6
else if roll < 93 then
x = 0.2 * x - 0.26 * y
y = 0.23 * xp + 0.22 * y + 1.6
else
x = -0.15 * x + 0.28 * y
y = 0.26 * xp + 0.24 * y + 0.44
end if
end for
...and here's the result:
Neat, huh?