diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 53b4422..9078761 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -17,6 +17,41 @@ function Library (ronin) { return ronin.surface.open(path) } + // Transforms + + this.move = (x, y) => { + ronin.surface.context.translate(x, y) + } + + this.rotate = (angle) => { + ronin.surface.context.rotate(angle) + } + + this.scale = (x, y) => { + ronin.surface.context.scale(x, y === undefined ? x : y) + } + + this.transform = (a, b, c, d, e, f) => { + // a:hscale b:hskew c:vskew d:vscale e:hmove f:vmove + ronin.surface.context.transform(a, b, c, d, e, f) + } + + this.setTransform = (a, b, c, d, e, f) => { + ronin.surface.context.setTransform(a, b, c, d, e, f) + } + + this.resetTransform = () => { + ronin.surface.context.resetTransform() + } + + this.pushTransform = () => { + ronin.surface.context.save() + } + + this.popTransform = () => { + ronin.surface.context.restore() + } + // Shapes this.pos = (x, y, t = 'pos') => { // Returns a position shape. @@ -241,7 +276,10 @@ function Library (ronin) { // Arrays this.map = async (fn, arr) => { - return Promise.all(arr.map(fn)) + for (let i = 0; i < arr.length; i++) { + const arg = arr[i]; + await fn(arg) + } } this.filter = (fn, arr) => { diff --git a/examples/transform.lisp b/examples/transform.lisp new file mode 100644 index 0000000..adb12f7 --- /dev/null +++ b/examples/transform.lisp @@ -0,0 +1,25 @@ +(resetTransform) +(clear) + +(defn branch + (v) + (if + (gt v 0) + ( + (scale 0.95) + (stroke + (line (pos 0 0) (pos 100 100)) + 10 "white") + (move 100 100) + (pushTransform) + (rotate (div v 50)) + (branch (sub v 1)) + (popTransform) + (pushTransform) + (rotate (div v -50)) + (branch (sub v 1)) + (popTransform) + ) + ) +) +(branch 10) \ No newline at end of file