From 1ead4a8c5c6c4d30c57e7fbb36c31f8e2185ac0a Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Sun, 3 Nov 2024 17:19:11 -0500 Subject: [PATCH] build --- build/ludus.mjs | 13 ++++++------- build/svg_test.mjs | 16 +++++++++------- build/svg_test.svg | 10 ++++------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/build/ludus.mjs b/build/ludus.mjs index 1fb3001..bf99997 100644 --- a/build/ludus.mjs +++ b/build/ludus.mjs @@ -10,13 +10,12 @@ export function run (source) { code = source const output = mod.ludus(source).value res = JSON.parse(output) - console.log(res) return res } export function stdout () { if (!res) return "" - return res.io.console.data + return res.io.stdout.data } export function turtle_commands () { @@ -135,7 +134,7 @@ function command_to_state (prev_state, curr_command) { return {...prev_state, heading: heading} } case "loadstate": { - console.log("LOADSTATE: ", curr_command) + // console.log("LOADSTATE: ", curr_command) const [_, [x, y], heading, visible, pendown, penwidth, pencolor] = curr_command return {position: [x, y], heading, visible, pendown, penwidth, pencolor} } @@ -270,7 +269,7 @@ function svg_render_turtle (state) { const pen_alpha = pa/255 const ink = pendown ? `` : "" return ` - + ${ink} @@ -278,14 +277,14 @@ function svg_render_turtle (state) { } export function svg (commands) { - console.log(commands) + // console.log(commands) const states = [turtle_init] commands.reduce((prev_state, command) => { const new_state = command_to_state(prev_state, command) states.push(new_state) return new_state }, turtle_init) - console.log(states) + // console.log(states) const {maxX, maxY, minX, minY} = states.reduce((accum, {position: [x, y]}) => { accum.maxX = Math.max(accum.maxX, x) accum.maxY = Math.max(accum.maxY, y) @@ -353,7 +352,7 @@ export function p5 (commands) { states.push(new_state) return new_state }, turtle_init) - console.log(states) + // console.log(states) const p5_calls = [...p5_call_root] for (let i = 1; i < states.length; ++i) { const prev = states[i - 1] diff --git a/build/svg_test.mjs b/build/svg_test.mjs index d44883c..9b69554 100644 --- a/build/svg_test.mjs +++ b/build/svg_test.mjs @@ -1,20 +1,22 @@ -import {run, svg} from "./ludus.mjs" +import {run, svg, stdout} from "./ludus.mjs" const code = ` - -let home = unbox (turtle_state) - +let start = unbox (turtle_state) fd! (100) +rt! (0.25) +fd! (100) -loadstate! (home) +loadstate! (start) +& home! () rt! (0.25) fd! (100) - -do turtle_state > unbox +lt! (0.25) ` const result = run(code) +// console.log(stdout(result)) + console.log(svg(result.io.turtle.data)) diff --git a/build/svg_test.svg b/build/svg_test.svg index 6568bf4..929b164 100644 --- a/build/svg_test.svg +++ b/build/svg_test.svg @@ -5,12 +5,12 @@ - + - + - + @@ -22,11 +22,9 @@ let home = unbox (turtle_state) -fd! (100) -rt! (0.25) fd! (100) -& loadstate! (home) +loadstate! (home) rt! (0.25) fd! (100)