diff --git a/build/ludus.jimage b/build/ludus.jimage index eeb861e..95ca5ea 100644 Binary files a/build/ludus.jimage and b/build/ludus.jimage differ diff --git a/build/ludus.mjs b/build/ludus.mjs index b46e98b..e26219c 100644 --- a/build/ludus.mjs +++ b/build/ludus.mjs @@ -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]} - } + const [_, color] = curr_command + return {...prev_state, pencolor: color} } 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 } diff --git a/build/out.mjs b/build/out.mjs index 57732fd..b4d614e 100644 --- a/build/out.mjs +++ b/build/out.mjs @@ -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 { diff --git a/build/out.wasm b/build/out.wasm index 8fcd8fe..3d23f0c 100755 Binary files a/build/out.wasm and b/build/out.wasm differ diff --git a/build/svg_test.svg b/build/svg_test.svg index 4c18c41..54ba2ef 100644 --- a/build/svg_test.svg +++ b/build/svg_test.svg @@ -1,4032 +1,12 @@ -[ 'pencolor', [ 0, 128, 128, 255 ] ] -[ 'pencolor', [ 192, 192, 192, 255 ] ] -[ 'pencolor', [ 255, 0, 0, 255 ] ] -[ 'pencolor', [ 0, 255, 0, 255 ] ] -[ 'pencolor', [ 128, 0, 0, 255 ] ] -[ 'pencolor', [ 255, 0, 255, 255 ] ] -[ 'pencolor', [ 255, 0, 255, 255 ] ] -[ 'pencolor', [ 0, 255, 0, 255 ] ] -[ 'pencolor', [ 128, 128, 0, 255 ] ] -[ 'pencolor', [ 128, 128, 0, 255 ] ] -[ 'pencolor', [ 0, 0, 255, 255 ] ] -[ 'pencolor', [ 0, 255, 25, 255 ] ] -[ 'pencolor', [ 255, 255, 255, 255 ] ] -[ 'pencolor', [ 255, 255, 0, 255 ] ] -[ 'pencolor', [ 128, 128, 128, 255 ] ] -[ 'pencolor', [ 0, 0, 128, 255 ] ] -[ 'pencolor', [ 128, 128, 128, 255 ] ] -[ 'pencolor', [ 128, 0, 128, 255 ] ] -[ 'pencolor', [ 0, 128, 128, 255 ] ] -[ 'pencolor', [ 128, 128, 128, 255 ] ] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + diff --git a/justfile b/justfile index 804e0c0..7cb8a75 100644 --- a/justfile +++ b/justfile @@ -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" diff --git a/prelude.ld b/prelude.ld index 696286b..a64a5fe 100644 --- a/prelude.ld +++ b/prelude.ld @@ -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