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_angle = 0.385
const turtle_color = [255, 255, 255, 150] let turtle_color = [255, 255, 255, 150]
const p5_call_root = [ function p5_call_root () {
["background", ...resolve_color(background_color)], return [
["push"], ["background", ...resolve_color(background_color)],
["rotate", Math.PI], ["push"],
["scale", -1, 1], ["rotate", Math.PI],
["stroke", ...resolve_color(turtle_init.pencolor)], ["scale", -1, 1],
] ["stroke", ...resolve_color(turtle_init.pencolor)],
]
}
function rotate (vector, heading) { function rotate (vector, heading) {
const radians = turn_to_rad(heading) const radians = turn_to_rad(heading)
@ -293,7 +295,8 @@ export function svg (commands) {
return accum return accum
}, {maxX: 0, maxY: 0, minX: 0, minY: 0}) }, {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_width = (maxX - minX) * 1.2
const view_height = (maxY - minY) * 1.2 const view_height = (maxY - minY) * 1.2
const margin = Math.max(view_width, view_height) * 0.1 const margin = Math.max(view_width, view_height) * 0.1
@ -353,7 +356,9 @@ export function p5 (commands) {
return new_state return new_state
}, turtle_init) }, turtle_init)
// console.log(states) // 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) { for (let i = 1; i < states.length; ++i) {
const prev = states[i - 1] const prev = states[i - 1]
const curr = states[i] const curr = states[i]