ludus-scripts/gons_recur.ld

45 lines
994 B
Plaintext

fn ngon! (sides, size) -> {
repeat sides {
forward! (size)
right! (div (1, sides))
}
:tada!
}
fn randcolor () -> (random (0, 255), random (0, 255), random (0, 255))
fn pen_randcolor! () -> pencolor! (randcolor ())
fn spiral_gon! (iter) -> {
loop (30, 0, colors :lime) with (size, times, color) -> {
let randcolor = (random(0, 255), random(0, 255), random (0, 255))
let newcolor = if eq? (color, colors :lime)
then colors :fuchsia
else colors :lime
if lt? (times, iter)
then {
pen_randcolor! ()
ngon! (5, size)
right! (inv (iter))
recur (add (size, 1), inc (times), newcolor)
}
else :ok
}
}
& spiral_gon! (100)
fn spiral_gonr! {
(iter) -> spiral_gonr! (iter, iter, 30)
(_, 0, _) -> :ok
(iter, times, size) -> {
pen_randcolor! ()
ngon! (4, size)
right! (inv (iter))
spiral_gonr! (iter, dec (times), inc (size))
}
}
goto! (37, 37)
spiral_gonr! (100)
print! (turtle_state())