Added "animate" binding, fixes #70

This commit is contained in:
Devine Lu Linvega 2019-07-22 14:50:05 +09:00
parent 00dc10894e
commit 7e99df545e
10 changed files with 46 additions and 54 deletions

View File

@ -50,7 +50,6 @@
ronin.controller.add("default","View","Expand Commander",() => { ronin.commander.toggle(true); },"CmdOrCtrl+Shift+K");
ronin.controller.add("default","Project","Run",() => { ronin.commander.run(); },"CmdOrCtrl+R");
ronin.controller.add("default","Project","Reload Run",() => { ronin.source.revert(); ronin.commander.run(); },"CmdOrCtrl+Shift+R");
ronin.controller.add("default","Project", "Animate",() => { ronin.animate(!ronin.always); },"CmdOrCtrl+Shift+T");
ronin.controller.add("default","Theme","Open Theme",() => { ronin.theme.open() },"CmdOrCtrl+Shift+O")
ronin.controller.add("default","Theme","Reset Theme",() => { ronin.theme.reset() },"CmdOrCtrl+Shift+Backspace")
ronin.controller.addSpacer('default', 'Theme', 'Download')

View File

@ -31,25 +31,13 @@ function Commander (ronin) {
this.hide()
}
this.cache = ''
this.run = (txt = this._input.value) => {
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
this.cache = txt
if (ronin.always !== true) {
ronin.bindings = {}
ronin.surface.maximize()
ronin.interpreter.run(this.cache)
}
}
this.loop = () => {
ronin.surface.maximize()
ronin.interpreter.run(this.cache)
ronin.always === true && requestAnimationFrame(() => this.loop())
ronin.interpreter.run(txt)
}
this.load = function (txt) {
ronin.animate(false)
this._input.value = txt
this.run(txt)
}

View File

@ -277,7 +277,7 @@ function Library (ronin) {
this.map = async (fn, arr) => {
for (let i = 0; i < arr.length; i++) {
const arg = arr[i];
const arg = arr[i]
await fn(arg)
}
}
@ -437,10 +437,6 @@ function Library (ronin) {
return (Date.now() * rate)
}
this.animate = (play = true) => { // Toggles animation.
ronin.animate(play)
}
this.js = () => { // Javascript interop.
return window
}

View File

@ -24,8 +24,6 @@ function Ronin () {
this.interpreter = new Lisp(this.library, this.includes)
this.osc = new Osc(this)
// Parameters
this.always = false
this.bindings = {}
this.install = function (host = document.body) {
@ -48,6 +46,14 @@ function Ronin () {
this.commander.start()
this.surface.start()
this.osc.start()
this.loop()
}
this.loop = () => {
if (this.bindings['animate'] && typeof this.bindings['animate'] === 'function') {
this.bindings['animate']()
}
requestAnimationFrame(() => this.loop())
}
this.reset = function () {
@ -62,12 +68,6 @@ function Ronin () {
}
this.animate = (b = true) => {
if (this.always === b) { return }
this.always = b
this.commander.loop()
}
this.bind = (event, fn) => {
this.bindings[event] = fn
}

View File

@ -1,6 +1,3 @@
;
(clear)
;
(def seg-count 50)
;
(def frame-middle
@ -47,4 +44,9 @@
(frame) :w) 0)
("rgba(255,255,255,0)" "white" "#72dec2" "red")))))
;
(times seg-count draw-dash)
(defn redraw
()
(
(clear)
(times seg-count draw-dash)))
(on "animate" redraw)

View File

@ -1,14 +0,0 @@
; filesystem
; print path
(echo
(filepath))
; print folder path
(echo
(dirpath))
; print file content
(echo
(file))
; print folder content
(echo
(dir))

View File

@ -57,3 +57,12 @@
; Interop
(test "interop" ((of (of (js) "Math") "max") 2 4) 4)
(test "recursive key selector" ((of (js) "Math" "max") 2 4) 4)
; fs
; filesystem
(echo (filepath))
(echo (dirpath))
(echo (file))
(echo (dir))

View File

@ -1 +0,0 @@
(echo (map '(add %1 2) (4 5 6))

View File

@ -13,3 +13,5 @@
(set ob :a 4)
(echo (of ob :a))
(echo (map '(add %1 2) (4 5 6))

View File

@ -1,13 +1,24 @@
;
(def ring
(circle 300 300 150))
;
(defn redraw
()
(
(clear)
(stroke ring 2 "red")))
;
(defn on-msg
(msg)
(
(clear)
(def msg-value
(of
(first msg) :value))
(stroke
(circle 300 300 150) 2
(if
(eq msg-value 1) "#ffb545" "#72dec2" ))))
(set ring :r 150)))
; frame
(set ring :r
(sub
(of ring :r) 1))
(redraw)
; trigger
(on "/a" on-msg)