Compare commits

...

2 Commits

Author SHA1 Message Date
Scott Richmond
a5e1aad83d release build 2025-07-06 18:54:45 -04:00
Scott Richmond
45d999d32e build + fix some turtle stuff 2025-07-06 18:54:10 -04:00
3 changed files with 16 additions and 8 deletions

View File

@ -1,4 +1,4 @@
import {eq_vect, eq_color, resolve_color, turtle_color, turtle_radius, turtle_angle, turn_to_rad, turtle_init, command_to_state, background_color, rotate, last} from "./turtle_geometry.js" import {eq_vect, eq_color, resolve_color, get_turtle_color, set_turtle_color, turtle_radius, turtle_angle, turn_to_rad, turtle_init, command_to_state, background_color, rotate, last} from "./turtle_geometry.js"
function states_to_call (prev, curr) { function states_to_call (prev, curr) {
const calls = [] const calls = []
@ -31,7 +31,7 @@ function p5_call_root () {
function p5_render_turtle (state, calls) { function p5_render_turtle (state, calls) {
if (!state.visible) return if (!state.visible) return
calls.push(["push"]) calls.push(["push"])
const [r, g, b, a] = turtle_color const [r, g, b, a] = get_turtle_color()
calls.push(["fill", r, g, b, a]) calls.push(["fill", r, g, b, a])
const {heading, pencolor, position: [x, y], pendown, penwidth} = state const {heading, pencolor, position: [x, y], pendown, penwidth} = state
const origin = [0, turtle_radius] const origin = [0, turtle_radius]
@ -69,10 +69,10 @@ export function p5 (commands) {
all_states[turtle_id].push(new_state) all_states[turtle_id].push(new_state)
} }
const [r, g, b, _] = resolve_color(background_color) const [r, g, b, _] = resolve_color(background_color)
if ((r + g + b)/3 > 128) turtle_color = [0, 0, 0, 150] if ((r + g + b)/3 > 128) set_turtle_color([0, 0, 0, 150])
const p5_calls = [...p5_call_root()] const p5_calls = [...p5_call_root()]
for (const states of Object.values(all_states)) { for (const states of Object.values(all_states)) {
console.log(states) // console.log(states)
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]

View File

@ -1,4 +1,4 @@
import {eq_vect, resolve_color, turtle_color, turtle_radius, rotate, turn_to_deg, command_to_state, turtle_init, background_color, turtle_angle, last} from "./turtle_geometry.js" import {eq_vect, resolve_color, set_turtle_color, get_turtle_color, turtle_radius, rotate, turn_to_deg, command_to_state, turtle_init, background_color, turtle_angle, last} from "./turtle_geometry.js"
function hex (n) { function hex (n) {
return n.toString(16).padStart(2, "0") return n.toString(16).padStart(2, "0")
@ -46,7 +46,7 @@ function svg_render_path (states) {
function svg_render_turtle (state) { function svg_render_turtle (state) {
if (!state.visible) return "" if (!state.visible) return ""
const [fr, fg, fb, fa] = turtle_color const [fr, fg, fb, fa] = get_turtle_color()
const fill_alpha = fa/255 const fill_alpha = fa/255
const {heading, pencolor, position: [x, y], pendown, penwidth} = state const {heading, pencolor, position: [x, y], pendown, penwidth} = state
const origin = [0, turtle_radius] const origin = [0, turtle_radius]
@ -89,7 +89,7 @@ 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) 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 = (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

View File

@ -11,7 +11,15 @@ export const turtle_radius = 20
export const turtle_angle = 0.385 export const turtle_angle = 0.385
export let turtle_color = [255, 255, 255, 150] let turtle_color = [255, 255, 255, 150]
export function get_turtle_color () {
return turtle_color
}
export function set_turtle_color (new_color) {
turtle_color = new_color
}
export const colors = { export const colors = {
black: [0, 0, 0, 255], black: [0, 0, 0, 255],