Compare commits
7 Commits
8eed4145db
...
27b1bb4e50
Author | SHA1 | Date | |
---|---|---|---|
|
27b1bb4e50 | ||
|
b8af13106a | ||
|
fc643cb561 | ||
|
43693e3c0e | ||
|
b31452db78 | ||
|
0a8dd3b7f7 | ||
|
ecc6438c3b |
Binary file not shown.
|
@ -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 _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 ___cxa_is_pointer_type = createExportWrapper('__cxa_is_pointer_type', 1);
|
||||||
var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5);
|
var dynCall_jiji = Module['dynCall_jiji'] = createExportWrapper('dynCall_jiji', 5);
|
||||||
var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1826680;
|
var ___emscripten_embedded_file_data = Module['___emscripten_embedded_file_data'] = 1826368;
|
||||||
function invoke_i(index) {
|
function invoke_i(index) {
|
||||||
var sp = stackSave();
|
var sp = stackSave();
|
||||||
try {
|
try {
|
||||||
|
|
BIN
build/out.wasm
BIN
build/out.wasm
Binary file not shown.
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@ludus/ludus-js-pure",
|
"name": "@ludus/ludus-js-pure",
|
||||||
"version": "0.1.18",
|
"version": "0.1.20",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@ludus/ludus-js-pure",
|
"name": "@ludus/ludus-js-pure",
|
||||||
"version": "0.1.18",
|
"version": "0.1.20",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"shadow-cljs": "^2.26.0",
|
"shadow-cljs": "^2.26.0",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@ludus/ludus-js-pure",
|
"name": "@ludus/ludus-js-pure",
|
||||||
"version": "0.1.18",
|
"version": "0.1.20",
|
||||||
"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",
|
||||||
|
|
26
prelude.ld
26
prelude.ld
|
@ -776,7 +776,7 @@ fn diff {
|
||||||
fn get {
|
fn get {
|
||||||
"Takes a key, dict, and optional default value; returns the value at key. If the value is not found, returns nil or the default value."
|
"Takes a key, dict, and optional default value; returns the value at key. If the value is not found, returns nil or the default value."
|
||||||
(key as :keyword) -> get (key, _)
|
(key as :keyword) -> get (key, _)
|
||||||
(key as :keyword, dict as :dict) -> get (key, dict)
|
(key as :keyword, dict as :dict) -> get (key, dict, nil)
|
||||||
(key as :keyword, dict as :dict, default) -> base :get (key, dict, default)
|
(key as :keyword, dict as :dict, default) -> base :get (key, dict, default)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1062,7 +1062,7 @@ let turtle_init = #{
|
||||||
:position (0, 0) & let's call this the origin for now
|
:position (0, 0) & let's call this the origin for now
|
||||||
:heading 0 & this is straight up
|
:heading 0 & this is straight up
|
||||||
:pendown? true
|
:pendown? true
|
||||||
:color colors :white
|
:pencolor colors :white
|
||||||
:penwidth 1
|
:penwidth 1
|
||||||
:visible? true
|
:visible? true
|
||||||
}
|
}
|
||||||
|
@ -1112,7 +1112,10 @@ fn render_turtle! () -> {
|
||||||
then {
|
then {
|
||||||
let (r, g, b, a) = turtle_color
|
let (r, g, b, a) = turtle_color
|
||||||
add_call! ((:fill, r, g, b, a))
|
add_call! ((:fill, r, g, b, a))
|
||||||
let #{heading, :position (x, y), ...} = state
|
let #{heading
|
||||||
|
:pencolor (pen_r, pen_g, pen_b, pen_a)
|
||||||
|
:position (x, y)
|
||||||
|
...} = state
|
||||||
let first = mult ((0, 1), turtle_radius)
|
let first = mult ((0, 1), turtle_radius)
|
||||||
let (x1, y1) = first
|
let (x1, y1) = first
|
||||||
let (x2, y2) = rotate (first, turtle_angle)
|
let (x2, y2) = rotate (first, turtle_angle)
|
||||||
|
@ -1127,7 +1130,7 @@ fn render_turtle! () -> {
|
||||||
add_call! ((:vertex, x3, y3))
|
add_call! ((:vertex, x3, y3))
|
||||||
add_call! ((:endShape))
|
add_call! ((:endShape))
|
||||||
& there's a happy bug here: the stroke will be the same width as the pen width. Keep this for now. Consider also showing the pen colour here?
|
& there's a happy bug here: the stroke will be the same width as the pen width. Keep this for now. Consider also showing the pen colour here?
|
||||||
add_call! ((:stroke, 0))
|
add_call! ((:stroke, pen_r, pen_g, pen_b, pen_a))
|
||||||
add_call! ((:line, 0, 0, x1, y1))
|
add_call! ((:line, 0, 0, x1, y1))
|
||||||
add_call! ((:pop))
|
add_call! ((:pop))
|
||||||
:ok
|
:ok
|
||||||
|
@ -1246,6 +1249,11 @@ fn goto! {
|
||||||
((x, y)) -> goto! (x, y)
|
((x, y)) -> goto! (x, y)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn setheading! {
|
||||||
|
"Sets the turtle's heading. The angle is specified in turns, with 0 pointing up. Increasing values rotate the turtle counter-clockwise."
|
||||||
|
(heading as :number) -> add_command! ((:setheading, heading))
|
||||||
|
}
|
||||||
|
|
||||||
fn heading/vector {
|
fn heading/vector {
|
||||||
"Takes a turtle heading, and returns a unit vector of that heading."
|
"Takes a turtle heading, and returns a unit vector of that heading."
|
||||||
(heading) -> {
|
(heading) -> {
|
||||||
|
@ -1258,8 +1266,10 @@ fn heading/vector {
|
||||||
fn apply_command {
|
fn apply_command {
|
||||||
"Takes a turtle state and a command and calculates a new state."
|
"Takes a turtle state and a command and calculates a new state."
|
||||||
(state, command) -> match command with {
|
(state, command) -> match command with {
|
||||||
(:goto, (x, y)) -> assoc (state, :position, (neg (x), y))
|
(:goto, (x, y)) -> assoc (state, :position, (x, y))
|
||||||
(:home) -> assoc (state, :position, (0, 0))
|
(:home) -> do state >
|
||||||
|
assoc (_, :position, (0, 0)) >
|
||||||
|
assoc (_, :heading, 0)
|
||||||
(:clear) -> assoc (state, :position, (0, 0))
|
(:clear) -> assoc (state, :position, (0, 0))
|
||||||
(:right, turns) -> update (state, :heading, add (_, turns))
|
(:right, turns) -> update (state, :heading, add (_, turns))
|
||||||
(:left, turns) -> update (state, :heading, sub (_, turns))
|
(:left, turns) -> update (state, :heading, sub (_, turns))
|
||||||
|
@ -1279,6 +1289,7 @@ fn apply_command {
|
||||||
(:pendown) -> assoc (state, :pendown?, true)
|
(:pendown) -> assoc (state, :pendown?, true)
|
||||||
(:penwidth, pixels) -> assoc (state, :penwidth, pixels)
|
(:penwidth, pixels) -> assoc (state, :penwidth, pixels)
|
||||||
(:pencolor, color) -> assoc (state, :pencolor, color)
|
(:pencolor, color) -> assoc (state, :pencolor, color)
|
||||||
|
(:setheading, heading) -> assoc (state, :heading, heading)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1319,7 +1330,7 @@ fn pencolor {
|
||||||
|
|
||||||
fn penwidth {
|
fn penwidth {
|
||||||
"Returns the turtle's pen width in pixels."
|
"Returns the turtle's pen width in pixels."
|
||||||
() -> turtle_state () :pencolor
|
() -> turtle_state () :penwidth
|
||||||
}
|
}
|
||||||
|
|
||||||
box state = nil
|
box state = nil
|
||||||
|
@ -1454,6 +1465,7 @@ pkg Prelude {
|
||||||
sentence & lists strings
|
sentence & lists strings
|
||||||
set & sets
|
set & sets
|
||||||
set? & sets
|
set? & sets
|
||||||
|
setheading! & turtles
|
||||||
show & strings
|
show & strings
|
||||||
sin & math
|
sin & math
|
||||||
slice & lists tuples strings
|
slice & lists tuples strings
|
||||||
|
|
|
@ -52,13 +52,14 @@
|
||||||
(comment
|
(comment
|
||||||
# (do
|
# (do
|
||||||
(def source `
|
(def source `
|
||||||
words ("foo bar ba,;;;!!!z")
|
forward! (100)
|
||||||
`)
|
`)
|
||||||
(def out (-> source
|
(def out (-> source
|
||||||
ludus
|
ludus
|
||||||
j/decode
|
j/decode
|
||||||
))
|
))
|
||||||
(setdyn :out stdout)
|
(setdyn :out stdout)
|
||||||
|
(pp out)
|
||||||
(def console (out "console"))
|
(def console (out "console"))
|
||||||
(print console)
|
(print console)
|
||||||
(def result (out "result"))
|
(def result (out "result"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user