Compare commits

...

3 Commits

Author SHA1 Message Date
Scott Richmond
d0a5128e0e fix turtle/path rotation, add p5 canvas transformations to adapter from web frontend 2024-10-20 14:17:39 -04:00
Scott Richmond
7dfaed11e3 0.1.28 2024-10-18 15:22:46 -04:00
Scott Richmond
deaeb7b4db build 2024-10-18 15:22:40 -04:00
5 changed files with 10 additions and 5 deletions

Binary file not shown.

View File

@ -191,8 +191,11 @@ const turtle_angle = 0.385
const turtle_color = [255, 255, 255, 150] const turtle_color = [255, 255, 255, 150]
const p5_call_root = [ const p5_call_root = [
["push"],
["rotate", Math.PI],
["scale", -1, 1],
["background", ...resolve_color(background_color)], ["background", ...resolve_color(background_color)],
["stroke", ...resolve_color(turtle_init.pencolor)] ["stroke", ...resolve_color(turtle_init.pencolor)],
] ]
function rotate (vector, heading) { function rotate (vector, heading) {
@ -324,7 +327,8 @@ function p5_render_turtle (state, calls) {
const [x2, y2] = rotate(origin, turtle_angle) const [x2, y2] = rotate(origin, turtle_angle)
const [x3, y3] = rotate(origin, -turtle_angle) const [x3, y3] = rotate(origin, -turtle_angle)
calls.push(["translate", x, y]) calls.push(["translate", x, y])
calls.push(["rotate", turn_to_rad(heading)]) // need negative turtle rotation with the other p5 translations
calls.push(["rotate", -turn_to_rad(heading)])
calls.push(["noStroke"]) calls.push(["noStroke"])
calls.push(["beginShape"]) calls.push(["beginShape"])
calls.push(["vertex", x1, y1]) calls.push(["vertex", x1, y1])
@ -353,6 +357,7 @@ export function p5 (commands) {
for (const call of calls) { for (const call of calls) {
p5_calls.push(call) p5_calls.push(call)
} }
p5_calls.push("pop")
} }
p5_calls[0] = ["background", ...resolve_color(background_color)] p5_calls[0] = ["background", ...resolve_color(background_color)]
p5_render_turtle(states[states.length - 1], p5_calls) p5_render_turtle(states[states.length - 1], p5_calls)

Binary file not shown.

4
package-lock.json generated
View File

@ -1,12 +1,12 @@
{ {
"name": "@ludus/ludus-js-pure", "name": "@ludus/ludus-js-pure",
"version": "0.1.27", "version": "0.1.28",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "@ludus/ludus-js-pure", "name": "@ludus/ludus-js-pure",
"version": "0.1.27", "version": "0.1.28",
"license": "GPL-3.0", "license": "GPL-3.0",
"devDependencies": { "devDependencies": {
"shadow-cljs": "^2.26.0", "shadow-cljs": "^2.26.0",

View File

@ -1,6 +1,6 @@
{ {
"name": "@ludus/ludus-js-pure", "name": "@ludus/ludus-js-pure",
"version": "0.1.27", "version": "0.1.28",
"description": "A Ludus interpreter in a pure JS function.", "description": "A Ludus interpreter in a pure JS function.",
"type": "module", "type": "module",
"main": "build/ludus.mjs", "main": "build/ludus.mjs",