Compare commits

...

2 Commits

Author SHA1 Message Date
Scott Richmond
14e4cf93ae release build 2025-07-07 13:25:50 -04:00
Scott Richmond
4134a69fcc improve svg background box logic 2025-07-07 13:25:31 -04:00

View File

@ -79,7 +79,7 @@ export function svg (commands, code) {
const new_state = command_to_state(prev_state, this_command) const new_state = command_to_state(prev_state, this_command)
all_states[turtle_id].push(new_state) all_states[turtle_id].push(new_state)
} }
let maxX = -Infinity, maxY = -Infinity, minX = Infinity, minY = Infinity let maxX = 0, maxY = 0, minX = 0, minY = 0
for (const states of Object.values(all_states)) { for (const states of Object.values(all_states)) {
for (const {position: [x, y]} of states) { for (const {position: [x, y]} of states) {
maxX = Math.max(maxX, x) maxX = Math.max(maxX, x)
@ -90,8 +90,8 @@ export function svg (commands, code) {
} }
const [r, g, b] = resolve_color(background_color) const [r, g, b] = resolve_color(background_color)
if ((r+g+b)/3 > 128) set_turtle_color([0, 0, 0, 150]) if ((r+g+b)/3 > 128) set_turtle_color([0, 0, 0, 150])
const view_width = (maxX - minX) * 1.2 const view_width = Math.max((maxX - minX) * 1.2, 200)
const view_height = (maxY - minY) * 1.2 const view_height = Math.max((maxY - minY) * 1.2, 200)
const margin = Math.max(view_width, view_height) * 0.1 const margin = Math.max(view_width, view_height) * 0.1
const x_origin = minX - margin const x_origin = minX - margin
const y_origin = -maxY - margin const y_origin = -maxY - margin