From 02ccd5327cd77062da882e9b10956991484fbd5f Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Tue, 10 Jun 2025 16:59:37 -0400 Subject: [PATCH] add document size in inches --- build/ludus.mjs | 2 +- build/svg_test.mjs | 66 +++++++++++++++++++++++++++++++++++++++------- build/svg_test.svg | 37 -------------------------- 3 files changed, 58 insertions(+), 47 deletions(-) delete mode 100644 build/svg_test.svg diff --git a/build/ludus.mjs b/build/ludus.mjs index 8632864..87bddf6 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 9b69554..8efbde8 100644 --- a/build/svg_test.mjs +++ b/build/svg_test.mjs @@ -1,18 +1,66 @@ import {run, svg, stdout} from "./ludus.mjs" const code = ` -let start = unbox (turtle_state) -fd! (100) -rt! (0.25) -fd! (100) +background! (colors :white) +pencolor! (colors :maroon) -loadstate! (start) -& home! () +fn ngon! (n, edge) -> { + repeat n { + forward! (edge) + right! (inv (n)) + } +} -rt! (0.25) -fd! (100) -lt! (0.25) +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) diff --git a/build/svg_test.svg b/build/svg_test.svg deleted file mode 100644 index 929b164..0000000 --- a/build/svg_test.svg +++ /dev/null @@ -1,37 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - -let home = unbox (turtle_state) - -fd! (100) - -loadstate! (home) - -rt! (0.25) -fd! (100) - -do turtle_state > unbox - - - - -