From 63b0b11510c623b3b847a084cf29fd39fb04b578 Mon Sep 17 00:00:00 2001 From: Scott Richmond Date: Thu, 2 Jan 2025 16:28:12 -0500 Subject: [PATCH] change turtle color based on background color so it's always visible --- build/ludus.mjs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/build/ludus.mjs b/build/ludus.mjs index bf99997..992ef88 100644 --- a/build/ludus.mjs +++ b/build/ludus.mjs @@ -189,15 +189,17 @@ const turtle_radius = 20 const turtle_angle = 0.385 -const turtle_color = [255, 255, 255, 150] +let turtle_color = [255, 255, 255, 150] -const p5_call_root = [ - ["background", ...resolve_color(background_color)], - ["push"], - ["rotate", Math.PI], - ["scale", -1, 1], - ["stroke", ...resolve_color(turtle_init.pencolor)], -] +function p5_call_root () { + return [ + ["background", ...resolve_color(background_color)], + ["push"], + ["rotate", Math.PI], + ["scale", -1, 1], + ["stroke", ...resolve_color(turtle_init.pencolor)], + ] +} function rotate (vector, heading) { const radians = turn_to_rad(heading) @@ -293,7 +295,8 @@ export function svg (commands) { return accum }, {maxX: 0, maxY: 0, minX: 0, minY: 0}) - const [r, g, b, a] = resolve_color(background_color) + const [r, g, b, a] = resolve_color(background_color) + if ((r+g+b)/3 > 128) turtle_color = [0, 0, 0, 150] const view_width = (maxX - minX) * 1.2 const view_height = (maxY - minY) * 1.2 const margin = Math.max(view_width, view_height) * 0.1 @@ -353,7 +356,9 @@ export function p5 (commands) { return new_state }, turtle_init) // console.log(states) - const p5_calls = [...p5_call_root] + const [r, g, b, _] = resolve_color(background_color) + if ((r + g + b)/3 > 128) turtle_color = [0, 0, 0, 150] + const p5_calls = [...p5_call_root()] for (let i = 1; i < states.length; ++i) { const prev = states[i - 1] const curr = states[i]