This commit is contained in:
Scott Richmond 2024-08-01 16:43:01 -04:00
parent 1085c7ae44
commit 4baabc0a20
7 changed files with 4049 additions and 26 deletions

Binary file not shown.

View File

@ -121,7 +121,6 @@ function command_to_state (prev_state, curr_command) {
return {...prev_state, penwidth: width}
}
case "pencolor": {
console.log(curr_command)
if (curr_command.length = 2) {
const [_, color] = curr_command
return {...prev_state, pencolor: color}
@ -211,7 +210,7 @@ function turn_to_rad (heading) {
}
function turn_to_deg (heading) {
return (heading * 360) + 180
return (heading * 360)
}
function svg_render_line (prev, curr) {
@ -283,16 +282,16 @@ export function svg (commands) {
const view_width = maxX - minX
const view_height = maxY - minY
const margin = Math.max(view_width, view_height) * 0.1
const x1 = minX - margin
const y1 = minY - margin
const x2 = maxX + margin
const y2 = maxY + margin
const x1 = Math.min(-300, (minX - margin))
const y1 = Math.min(-300, (minY - margin))
const x2 = Math.max(600, (maxX + margin))
const y2 = Math.max(600, (maxY + margin))
const path = svg_render_path(states)
const turtle = svg_render_turtle(states[states.length - 1])
return `<?xml version="1.0" xmlns="http://www.w3.org/2000/svg" standalone="no"?>
<svg version="1.1" style="background-color:rgb(${r} ${g} ${b}); background-opacity: ${a/255}" viewBox="${x1} ${y1} ${x2} ${y2}">
return `<?xml version="1.0" standalone="no"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" style="background-color:rgb(${r} ${g} ${b}); background-opacity: ${a/255}" viewBox="${x1} ${y1} ${x2} ${y2}">
<g>
<g transform="scale(-1, 1) rotate(180)">
${path}
${turtle}
</g>

View File

@ -6489,7 +6489,7 @@ var __emscripten_stack_alloc = (a0) => (__emscripten_stack_alloc = wasmExports['
var _emscripten_stack_get_current = () => (_emscripten_stack_get_current = wasmExports['emscripten_stack_get_current'])();
var ___cxa_is_pointer_type = createExportWrapper('__cxa_is_pointer_type', 1);
var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5);
var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1820072;
var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1819920;
function invoke_i(index) {
var sp = stackSave();
try {

Binary file not shown.

View File

@ -1,10 +1,14 @@
import {run, svg} from "./ludus.mjs"
const code = `
forward! (100)
right! (0.25)
forward! (100)
`
repeat 20 {
repeat 100 {
fd! (4)
rt! (0.01)
}
pencolor! (random (colors))
rt! (inv (20))
}`
const result = run(code)

File diff suppressed because it is too large Load Diff

Before

Width:  |  Height:  |  Size: 937 B

After

Width:  |  Height:  |  Size: 338 KiB

View File

@ -1159,9 +1159,9 @@ let pd! = pendown!
fn pencolor! {
"Changes the turtle's pen color. Takes a single grayscale value, an rgb tuple, or an rgba tuple. Alias: pc!"
(color as :keyword) -> add_command! ((:pencolor, color))
(gray as :number) -> add_command! ((:pencolor, (gray, gray, gray, 255)))
((r as :number, g as :number, b as :number)) -> add_command! ((:pencolor, (r, g, b, 255)))
((r as :number, g as :number, b as :number, a as :number)) -> add_command! ((:pencolor, (r, g, b, a)))
(gray as :number) -> add_command! ((:pencolor, gray, gray, gray, 255))
((r as :number, g as :number, b as :number)) -> add_command! ((:pencolor, r, g, b, 255))
((r as :number, g as :number, b as :number, a as :number)) -> add_command! ((:pencolor, r, g, b, a))
}
let pc! = pencolor!