From 6f666c86dd2196d689ee52c6b50d537532f11d35 Mon Sep 17 00:00:00 2001 From: Devine Lu Linvega Date: Fri, 26 Jul 2019 09:51:55 +0900 Subject: [PATCH] Ported some examples --- desktop/sources/lisp/prelude.lisp | 8 +------- desktop/sources/scripts/commander.js | 14 +++++-------- examples/basics/gradients.lisp | 30 +++++++++++----------------- examples/basics/shapes.lisp | 6 +++--- examples/demo/fog.lisp | 1 - examples/demo/spiral.lisp | 1 - examples/events/on-animate.lisp | 12 ++++------- examples/events/on-mouse.lisp | 8 ++++---- examples/misc/theme.lisp | 3 +-- 9 files changed, 30 insertions(+), 53 deletions(-) diff --git a/desktop/sources/lisp/prelude.lisp b/desktop/sources/lisp/prelude.lisp index 4bf7134..2163b10 100644 --- a/desktop/sources/lisp/prelude.lisp +++ b/desktop/sources/lisp/prelude.lisp @@ -1,16 +1,10 @@ ; (echo "Loading prelude.lisp") -; -(def frame-rect (frame)) ; translate (defn translate (r p) (clone r - (rect - (of p :x) - (of p :y) - (of r :w) - (of r :h)))) + (rect p:x p:y r:w r:h))) ; times (defn times (v f) diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 8893be3..283610c 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -204,22 +204,18 @@ function Commander (ronin) { // Splash - this.splash = `; welcome to ronin - v2.1 + this.splash = `; welcome to ronin - v2.2 (clear) ; ronin path (def align { - :x (sub (of (frame) :c) 500) - :y (sub (of (frame) :m) 150)}) + :x (sub frame-rect:c 500) + :y (sub frame-rect:m 150)}) ; outline (fill - (svg - (of align :x) - (of align :y) "M15,15 L15,15 L285,15 L285,285 L15,285 Z") "#fff") + (svg align:x align:y "M15,15 L15,15 L285,15 L285,285 L15,285 Z") "#fff") ; stroke (stroke - (svg - (of align :x) - (of align :y) "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") 5 "#000")` + (svg align:x align:y "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") 5 "#000")` String.prototype.insert = function (s, i) { return [this.slice(0, i), `${s}`, this.slice(i)].join('') } } diff --git a/examples/basics/gradients.lisp b/examples/basics/gradients.lisp index 1a767db..039411f 100644 --- a/examples/basics/gradients.lisp +++ b/examples/basics/gradients.lisp @@ -1,31 +1,25 @@ ; gradients (clear) ; -(def radius (of (frame) :m)) +(def radius frame-rect:m) ; (def gradient-line - (line - (of (frame) :c) 0 - (of (frame) :c) - (of (frame) :h))) + (line frame-rect:c 0 frame-rect:c + frame-rect:h)) ; (fill - (circle - (of (frame) :c) - (of (frame) :m) - radius) - (gradient gradient-line ("#72dec2" "white"))) + (circle frame-rect:c frame-rect:m radius) + (gradient gradient-line + ("#72dec2" "white"))) ; (fill - (circle - (of (frame) :c) - (of (frame) :m) + (circle frame-rect:c frame-rect:m (mul radius 0.75)) - (gradient gradient-line ("white" "#72dec2"))) + (gradient gradient-line + ("white" "#72dec2"))) ; (fill - (circle - (of (frame) :c) - (of (frame) :m) + (circle frame-rect:c frame-rect:m (mul radius 0.5)) - (gradient gradient-line ("#72dec2" "white"))) \ No newline at end of file + (gradient gradient-line + ("#72dec2" "white"))) \ No newline at end of file diff --git a/examples/basics/shapes.lisp b/examples/basics/shapes.lisp index d97ecfe..698f995 100644 --- a/examples/basics/shapes.lisp +++ b/examples/basics/shapes.lisp @@ -3,9 +3,9 @@ (clear) ; variables -(def center-w (div (of (frame) "w") 2)) -(def center-h (div (of (frame) "h") 2)) -(def rad (div (of (frame) "h") 4)) +(def center-w (div frame-rect:w 2)) +(def center-h (div frame-rect:h 2)) +(def rad (div frame-rect:h 4)) ; draw circle (stroke diff --git a/examples/demo/fog.lisp b/examples/demo/fog.lisp index 403f56a..d742e9a 100644 --- a/examples/demo/fog.lisp +++ b/examples/demo/fog.lisp @@ -2,7 +2,6 @@ (resetTransform) (clear) ; -(def frame-rect (frame)) (def mouse-pos (pos)) (def prev-pos (pos)) ; diff --git a/examples/demo/spiral.lisp b/examples/demo/spiral.lisp index 6f91895..7f083ef 100644 --- a/examples/demo/spiral.lisp +++ b/examples/demo/spiral.lisp @@ -1,6 +1,5 @@ ; animated recusive spiral ; by @local_guru -(def frame-rect (frame)) (defn rec (v) (if (gt v 0) diff --git a/examples/events/on-animate.lisp b/examples/events/on-animate.lisp index 569396f..5a177e7 100644 --- a/examples/events/on-animate.lisp +++ b/examples/events/on-animate.lisp @@ -4,13 +4,11 @@ ; (def frame-middle (div - (of - (frame) :h) 2)) + frame-rect:h 2)) ; (def seg-width (div - (of - (frame) :w) seg-count)) + frame-rect:w seg-count)) ; (defn elevation (i) @@ -21,8 +19,7 @@ (time 0.001) (div i 5))) (div - (of - (frame) :h) 5)) frame-middle)) + frame-rect:h 5)) frame-middle)) ; (defn draw-dash (i) @@ -40,8 +37,7 @@ (elevation i)) 4 (gradient (line 50 0 - (of - (frame) :w) 0) + frame-rect:w 0) ("#ffb545" "#72dec2"))))) ; (defn redraw diff --git a/examples/events/on-mouse.lisp b/examples/events/on-mouse.lisp index 165dd59..595aa72 100644 --- a/examples/events/on-mouse.lisp +++ b/examples/events/on-mouse.lisp @@ -4,15 +4,15 @@ ( (clear) ; vertical line - (stroke (line (of e :x) 0 (of e :x) (of e :y)) 2 "#ff0000") + (stroke (line e:x 0 e:x e:y) 2 "#ff0000") ; horizontal line (stroke - (line 0 (of e :y) (of e :x) (of e :y)) 2 "#72dec2") + (line 0 (of e :y) e:x e:y) 2 "#72dec2") ; circle (stroke (circle - (of e :x) - (of e :y) 30) 2 "#ffffff"))) + e:x + e:y 30) 2 "#ffffff"))) ; (on "mouse-down" redraw) (on "mouse-up" redraw) diff --git a/examples/misc/theme.lisp b/examples/misc/theme.lisp index 8c2dbe7..1aa5fce 100644 --- a/examples/misc/theme.lisp +++ b/examples/misc/theme.lisp @@ -25,8 +25,7 @@ (circle (add (div - (of - (frame) "w") 1.6) + frame-rect:w 1.6) (mul 1.5 v)) (mul 10 v) (mul v