diff --git a/desktop/sources/lisp/prelude.lisp b/desktop/sources/lisp/prelude.lisp new file mode 100644 index 0000000..82c0999 --- /dev/null +++ b/desktop/sources/lisp/prelude.lisp @@ -0,0 +1,11 @@ +(echo "Loading prelude.lisp") + +(defn translate + (r p) + (clone + r + (rect + (of p :x) + (of p :y) + (of r :w) + (of r :h)))) diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js index 07b4165..46a55d4 100644 --- a/desktop/sources/scripts/lisp.js +++ b/desktop/sources/scripts/lisp.js @@ -167,10 +167,12 @@ function Lisp (input, lib) { } this.parse = function (input) { - return parenthesize(tokenize(`(${input})`)) + return parenthesize(tokenize(input)) } this.toPixels = async function () { - return interpret(this.parse(input)) + return interpret(this.parse(`( + (include "./sources/lisp/prelude.lisp") + ${input})`)) } } diff --git a/examples/glitch.lisp b/examples/glitch.lisp index 5491fc8..064d5e1 100644 --- a/examples/glitch.lisp +++ b/examples/glitch.lisp @@ -5,12 +5,11 @@ (defn glitch (rec) (if (gt rec 1) - ((clone - (rect (random 400) (random 400) 2 2) - (rect (random 400) (random 400) -(random 10) (random 30))) - (glitch (sub rec 1)))) -) + ( + (translate + (rect (random 400) (random 400) (random 10) (random 10)) + (pos (random 400) (random 400))) + (glitch (sub rec 1))))) (import "../static/crystal.jpg"