71 lines
1.3 KiB
JavaScript
71 lines
1.3 KiB
JavaScript
import {run, svg, stdout} from "./ludus.mjs"
|
|
|
|
const code = `
|
|
background! (colors :white)
|
|
pencolor! (colors :maroon)
|
|
|
|
fn ngon! (n, edge) -> {
|
|
repeat n {
|
|
forward! (edge)
|
|
right! (inv (n))
|
|
}
|
|
}
|
|
|
|
fn cngon! (n, radius) -> {
|
|
let angle = add (inv (4), inv (mult (2, n)))
|
|
let edge = mult (2, radius, sin (inv (mult (2, n))))
|
|
|
|
penup! ()
|
|
forward! (radius)
|
|
right! (angle)
|
|
pendown! ()
|
|
ngon! (n, edge)
|
|
left! (angle)
|
|
penup! ()
|
|
back! (radius)
|
|
pendown! ()
|
|
}
|
|
|
|
fn twisty_nonagons! (times, iter, radius, growth) -> {
|
|
if gte? (iter, times) then :ok
|
|
else {
|
|
cngon! (9, radius)
|
|
right! (inv (times))
|
|
twisty_nonagons! (times, inc (iter), add (radius, growth), growth)
|
|
}
|
|
}
|
|
|
|
twisty_nonagons! (10, 0, 100, 3)
|
|
|
|
fn centre_squares! (times, radius, growth) -> {
|
|
if lt? (times, 1) then :ok
|
|
else {
|
|
cngon! (4, radius)
|
|
centre_squares! (dec (times), add (radius, growth), growth)
|
|
}
|
|
}
|
|
|
|
& right! (0.125)
|
|
& centre_squares! (10, 100, 4)
|
|
|
|
fn twisty_triangles! (times, radius, angle, growth) -> {
|
|
if lt? (times, 1) then :ok
|
|
else {
|
|
cngon! (3, radius)
|
|
right! (angle)
|
|
twisty_triangles! (dec (times), sub (radius, growth), angle, growth)
|
|
}
|
|
}
|
|
|
|
& right! (inv (6))
|
|
& twisty_triangles! (8, 100, inv (120), 10)
|
|
|
|
& hideturtle! ()
|
|
`
|
|
|
|
const result = run(code)
|
|
|
|
// console.log(stdout(result))
|
|
|
|
console.log(svg(result.io.turtle.data))
|