This commit is contained in:
Scott Richmond 2024-08-01 17:05:41 -04:00
parent 4baabc0a20
commit d477782ff6
7 changed files with 21 additions and 4061 deletions

Binary file not shown.

View File

@ -121,25 +121,15 @@ function command_to_state (prev_state, curr_command) {
return {...prev_state, penwidth: width}
}
case "pencolor": {
if (curr_command.length = 2) {
const [_, color] = curr_command
return {...prev_state, pencolor: color}
} else {
const [_, r, g, b, a] = curr_command
return {...prev_state, pencolor: [r, g, b, a]}
}
}
case "setheading": {
const [_, heading] = curr_command
return {...prev_state, heading: heading}
}
case "loadstate": {
const [_, x, y, heading, visible, pendown, penwidth] = curr_command
// there are 7 fixed-arity arguments
// color will either be the last one or four
let pencolor = curr_command.slice(7)
// if there's one, it's a string, unpack it
if (pencolor.length = 1) pencolor = pencolor[0]
const [_, x, y, heading, visible, pendown, penwidth, pencolor] = curr_command
return {position: [x, y], heading, visible, pendown, penwidth, pencolor}
}
case "show": {
@ -149,9 +139,7 @@ function command_to_state (prev_state, curr_command) {
return {...prev_state, visible: false}
}
case "background": {
let color = curr_command.slice(1)
if (color.lengh = 1) color = color[0]
background_color = color
background_color = curr_command.slice(1)
return prev_state
}
}
@ -344,7 +332,7 @@ export function p5_calls (commands) {
p5_calls.push(call)
}
}
p5_calls[0] = ["background", ...resolve_color(background_color)]
p5_calls[0] = ["background", background_color]
p5_render_turtle(states[states.length - 1], p5_calls)
return p5_calls
}

View File

@ -6489,7 +6489,7 @@ var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['
var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();
var ___cxa_is_pointer_type = createExportWrapper('__cxa_is_pointer_type', 1);
var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5);
var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1819920;
var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1816028;
function invoke_i(index) {
var sp = stackSave();
try {

Binary file not shown.

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 338 KiB

After

Width:  |  Height:  |  Size: 722 B

View File

@ -23,9 +23,9 @@ publish:
# build the ludus jimage
build:
rm build/out.mjs
rm build/out.wasm
rm build/ludus.jimage
rm -f build/out.mjs
rm -f build/out.wasm
rm -f build/ludus.jimage
janet -c src/ludus.janet build/ludus.jimage
cd build && just build
git commit -am "build"

View File

@ -1159,9 +1159,9 @@ let pd! = pendown!
fn pencolor! {
"Changes the turtle's pen color. Takes a single grayscale value, an rgb tuple, or an rgba tuple. Alias: pc!"
(color as :keyword) -> add_command! ((:pencolor, color))
(gray as :number) -> add_command! ((:pencolor, gray, gray, gray, 255))
((r as :number, g as :number, b as :number)) -> add_command! ((:pencolor, r, g, b, 255))
((r as :number, g as :number, b as :number, a as :number)) -> add_command! ((:pencolor, r, g, b, a))
(gray as :number) -> add_command! ((:pencolor, (gray, gray, gray, 255)))
((r as :number, g as :number, b as :number)) -> add_command! ((:pencolor, (r, g, b, 255)))
((r as :number, g as :number, b as :number, a as :number)) -> add_command! ((:pencolor, (r, g, b, a)))
}
let pc! = pencolor!
@ -1176,9 +1176,9 @@ let pw! = penwidth!
fn background! {
"Sets the background color behind the turtle and path. Alias: bg!"
(color as :keyword) -> add_command! ((:background, color))
(gray as :number) -> add_command! ((:background, gray, gray, gray, 255))
((r as :number, g as :number, b as :number)) -> add_command! ((:background, r, g, b, 255))
((r as :number, g as :number, b as :number, a as :number)) -> add_command! ((:background, r, g, b, a))
(gray as :number) -> add_command! ((:background, (gray, gray, gray, 255)))
((r as :number, g as :number, b as :number)) -> add_command! ((:background, (r, g, b, 255)))
((r as :number, g as :number, b as :number, a as :number)) -> add_command! ((:background, (r, g, b, a)))
}
let bg! = background!
@ -1215,17 +1215,10 @@ fn hideturtle! {
}
fn loadstate! {
"Sets the turtle state to a previously saved state. Returns the state."
"Sets the turtle state to a previously saved state."
(state) -> {
let #{:position (x, y), heading, pendown?, pencolor, penwidth, visible?} = state
let command = if tuple? (pencolor)
then {
let (r, g, b, a) = pencolor
(:loadstate, x, y, heading, visible?, pendown?, penwidth, r, g, b, a)
}
else (:loadstate, x, y, heading, visible?, pendown?, penwidth, pencolor)
add_command! (command)
state
let #{position, heading, pendown?, pencolor, penwidth, visible?} = state
add_command! ((:loadstate, position, heading, visible?, pendown?, penwidth, pencolor))
}
}
@ -1258,8 +1251,7 @@ fn apply_command {
(:penwidth, pixels) -> assoc (state, :penwidth, pixels)
(:pencolor, color) -> assoc (state, :pencolor, color)
(:setheading, heading) -> assoc (state, :heading, heading)
(:loadstate, x, y, heading, visible?, pendown?, penwidth, pencolor) -> #{:position (x, y), heading, visible?, pendown?, penwidth, pencolor}
(:loadstate, x, y, heading, visible?, pendown?, penwidth, r, g, b, a) -> #{:position (x, y), heading, visible?, pendown?, penwidth, :pencolor (r, g, b, a)}
(:loadstate, position, heading, visible?, pendown?, penwidth, pencolor) -> #{position, heading, visible?, pendown?, penwidth, pencolor}
(:show) -> assoc (state, :visible?, true)
(:hide) -> assoc (state, :visible?, false)
(:background, _) -> state