change turtle color based on background color so it's always visible

This commit is contained in:
Scott Richmond 2025-01-02 16:28:12 -05:00
parent 5de97b8a9c
commit 63b0b11510

View File

@ -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)
@ -294,6 +296,7 @@ export function svg (commands) {
}, {maxX: 0, maxY: 0, minX: 0, minY: 0})
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]