fix p5 call push/pop errors

This commit is contained in:
Scott Richmond 2024-10-20 14:39:36 -04:00
parent fd55dd9a50
commit 12f1a85e27
2 changed files with 4 additions and 9 deletions

View File

@ -191,10 +191,10 @@ const turtle_angle = 0.385
const turtle_color = [255, 255, 255, 150] const turtle_color = [255, 255, 255, 150]
const p5_call_root = [ const p5_call_root = [
["background", ...resolve_color(background_color)],
["push"], ["push"],
["rotate", Math.PI], ["rotate", Math.PI],
["scale", -1, 1], ["scale", -1, 1],
["background", ...resolve_color(background_color)],
["stroke", ...resolve_color(turtle_init.pencolor)], ["stroke", ...resolve_color(turtle_init.pencolor)],
] ]
@ -357,10 +357,10 @@ export function p5 (commands) {
for (const call of calls) { for (const call of calls) {
p5_calls.push(call) p5_calls.push(call)
} }
p5_calls.push(["pop"])
} }
p5_calls[0] = ["background", ...resolve_color(background_color)] p5_calls[0] = ["background", ...resolve_color(background_color)]
p5_render_turtle(states[states.length - 1], p5_calls) p5_render_turtle(states[states.length - 1], p5_calls)
p5_calls.push(["pop"])
return p5_calls return p5_calls
} }

View File

@ -3,13 +3,8 @@ import {run, p5} from "./ludus.mjs"
const code = ` const code = `
print! ("Hello, world!") print! ("Hello, world!")
pencolor! (colors :white) pencolor! (colors :white)
repeat 10 { fd! (50)
repeat 4 { `
fd! (500)
rt! (0.25)
}
rt! (0.1)
}`
const result = run(code) const result = run(code)