diff --git a/build/ludus.mjs b/build/ludus.mjs index 87bddf6..508e669 100644 --- a/build/ludus.mjs +++ b/build/ludus.mjs @@ -309,7 +309,7 @@ export function svg (commands) { const path = svg_render_path(states) const turtle = svg_render_turtle(states[states.length - 1]) return ` - + diff --git a/build/svg_test.mjs b/build/svg_test.mjs index 8efbde8..646e899 100644 --- a/build/svg_test.mjs +++ b/build/svg_test.mjs @@ -1,66 +1,33 @@ import {run, svg, stdout} from "./ludus.mjs" const code = ` -background! (colors :white) -pencolor! (colors :maroon) + penwidth!(7) +pencolor!(:red) +background!(:maroon) -fn ngon! (n, edge) -> { - repeat n { - forward! (edge) - right! (inv (n)) +fn ngon! (num_sides, side_len) -> { + repeat num_sides { + forward! (side_len) + right! (inv (num_sides)) } } -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 show_gons! (n, side_len) -> { + if lte? (n, 0) + then :ok + else { + ngon! (n, side_len) + penup!() + rt!(0.01) + fd!(add (side_len, 10)) + pendown!() + show_gons! (sub (n, 1), side_len) + } } -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) - } -} +show_gons! (100, 100) -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! () +hideturtle!() ` const result = run(code) diff --git a/package.json b/package.json index eefabec..93da944 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ludus/ludus-js-pure", - "version": "0.1.38", + "version": "0.1.37", "description": "A Ludus interpreter in a pure JS function.", "type": "module", "main": "build/ludus.mjs",