From 39984ac537ad748702816b9a4195dda98360e4cc Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Fri, 2 Aug 2024 14:55:46 -0400 Subject: [PATCH] build --- build/ludus.mjs | 24 ++++++++++------ build/svg_test.svg | 72 +++++++++++++++++++++++----------------------- 2 files changed, 51 insertions(+), 45 deletions(-) diff --git a/build/ludus.mjs b/build/ludus.mjs index 32a7171..e2a272b 100644 --- a/build/ludus.mjs +++ b/build/ludus.mjs @@ -145,27 +145,33 @@ function command_to_state (prev_state, curr_command) { } } -function are_eq (v1, v2) { +function eq_vect (v1, v2) { const [x1, y1] = v1 const [x2, y2] = v2 return (x1 === x2) && (y1 === y2) } +function eq_color (c1, c2) { + if (c1 === c2) return true + const res1 = resolve_color(c1) + const res2 = resolve_color(c2) + for (let i = 0; i < res1.length; ++i) { + if (res1[i] !== res2[i]) return false + } + return true +} + function states_to_call (prev, curr) { const calls = [] // whose state should we use? // pen states will only differ on more than one property // if we use `loadstate` // my sense is `prev`, but that may change - if (prev.pendown && !are_eq(prev.position, curr.position)) { + if (prev.pendown && !eq_vect(prev.position, curr.position)) { calls.push(["line", prev.position[0], prev.position[1], curr.position[0], curr.position[1]]) } - if (curr.pencolor !== prev.pencolor) { - if (Array.isArray(curr.pencolor)) { - calls.push(["stroke", ...curr.pencolor]) - } else { - calls.push(["stroke", curr.pencolor]) - } + if (!eq_color(curr.pencolor, prev.pencolor)) { + calls.push(["stroke", ...resolve_color(curr.pencolor)]) } if (curr.penwidth !== prev.penwidth) { calls.push(["strokeWeight", curr.penwidth]) @@ -203,7 +209,7 @@ function turn_to_deg (heading) { function svg_render_line (prev, curr) { if (!prev.pendown) return "" - if (are_eq(prev.position, curr.position)) return "" + if (eq_vect(prev.position, curr.position)) return "" const {position: [x1, y1], pencolor, penwidth} = prev const {position: [x2, y2]} = curr const [r, g, b, a] = resolve_color(pencolor) diff --git a/build/svg_test.svg b/build/svg_test.svg index 46be249..8b9d844 100644 --- a/build/svg_test.svg +++ b/build/svg_test.svg @@ -1,5 +1,5 @@ - + @@ -15,76 +15,76 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +