add document size in inches

This commit is contained in:
Scott Richmond 2025-06-10 16:59:37 -04:00
parent d76a08cfe3
commit 02ccd5327c
3 changed files with 58 additions and 47 deletions

View File

@ -309,7 +309,7 @@ export function svg (commands) {
const path = svg_render_path(states)
const turtle = svg_render_turtle(states[states.length - 1])
return `<?xml version="1.0" standalone="no"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${x_origin} ${y_origin} ${view_width} ${view_height}">
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" viewBox="${x_origin} ${y_origin} ${view_width} ${view_height}" width="10in", height="8in">
<rect x="${x_origin - 5}" y="${y_origin - 5}" width="${view_width + 10}" height="${view_height + 10}" fill="#${hex(r)}${hex(g)}${hex(b)}" stroke-width="0" paint-order="fill" />

View File

@ -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)

View File

@ -1,37 +0,0 @@
<?xml version="1.0" standalone="no"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="background-color:rgb(0 0 0); background-opacity: 1" viewBox="-12 -112 120 120">
<g transform="scale(-1, 1) rotate(180)">
<line x1="0" y1="0" x2="6.123233995736766e-15" y2="100" stroke="rgb(255 255 255)" stroke-opacity="1" stroke-width="1"/>
<line x1="6.123233995736766e-15" y1="100" x2="0" y2="0" stroke="rgb(255 255 255)" stroke-opacity="1" stroke-width="1"/>
<line x1="0" y1="0" x2="100" y2="0" stroke="rgb(255 255 255)" stroke-opacity="1" stroke-width="1"/>
<g transform="translate(100, 0)rotate(90)">
<polygon points="0 20 -13.226237306473037 -15.00222139260919 13.226237306473037 -15.00222139260919" stroke="none" fill="rgb(255 255 255)" fill-opacity="0.5882352941176471"/>
<line x1="0" y1="20" x2="0" y2="0" stroke="rgb(255 255 255)" stroke-opacity="1" stroke-width="1" />
</g>
</g>
<ludus>
let home = unbox (turtle_state)
fd! (100)
loadstate! (home)
rt! (0.25)
fd! (100)
do turtle_state &gt; unbox
</ludus>
</svg>

Before

Width:  |  Height:  |  Size: 1.1 KiB