Compare commits
2 Commits
cce3a2410f
...
a5e1aad83d
Author | SHA1 | Date | |
---|---|---|---|
|
a5e1aad83d | ||
|
45d999d32e |
|
@ -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) {
|
||||
const calls = []
|
||||
|
@ -31,7 +31,7 @@ function p5_call_root () {
|
|||
function p5_render_turtle (state, calls) {
|
||||
if (!state.visible) return
|
||||
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])
|
||||
const {heading, pencolor, position: [x, y], pendown, penwidth} = state
|
||||
const origin = [0, turtle_radius]
|
||||
|
@ -69,10 +69,10 @@ export function p5 (commands) {
|
|||
all_states[turtle_id].push(new_state)
|
||||
}
|
||||
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()]
|
||||
for (const states of Object.values(all_states)) {
|
||||
console.log(states)
|
||||
// console.log(states)
|
||||
for (let i = 1; i < states.length; ++i) {
|
||||
const prev = states[i - 1]
|
||||
const curr = states[i]
|
||||
|
|
|
@ -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) {
|
||||
return n.toString(16).padStart(2, "0")
|
||||
|
@ -46,7 +46,7 @@ function svg_render_path (states) {
|
|||
|
||||
function svg_render_turtle (state) {
|
||||
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 {heading, pencolor, position: [x, y], pendown, penwidth} = state
|
||||
const origin = [0, turtle_radius]
|
||||
|
@ -89,7 +89,7 @@ export function svg (commands, code) {
|
|||
}
|
||||
}
|
||||
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_height = (maxY - minY) * 1.2
|
||||
const margin = Math.max(view_width, view_height) * 0.1
|
||||
|
|
|
@ -11,7 +11,15 @@ export const turtle_radius = 20
|
|||
|
||||
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 = {
|
||||
black: [0, 0, 0, 255],
|
||||
|
|
Loading…
Reference in New Issue
Block a user