From 0f2acc0d0e8690a88a863fac37018f3059d0eb55 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 20 Jul 2019 21:25:28 +0200 Subject: [PATCH] add prelude.lisp --- desktop/sources/lisp/prelude.lisp | 11 +++++++++++ desktop/sources/scripts/lisp.js | 6 ++++-- examples/glitch.lisp | 11 +++++------ 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 desktop/sources/lisp/prelude.lisp 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"