add animation

This commit is contained in:
Quentin Leonetti 2019-07-14 15:25:12 +02:00
parent 391874841b
commit fccfb598d9
4 changed files with 24 additions and 2 deletions

View File

@ -42,6 +42,7 @@
ronin.controller.addRole('default', 'Edit', 'selectall') ronin.controller.addRole('default', 'Edit', 'selectall')
ronin.controller.add("default","Project","Run",() => { ronin.commander.run(); },"CmdOrCtrl+R"); 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","Reload Run",() => { ronin.source.revert(); ronin.commander.run(); },"CmdOrCtrl+Shift+R");
ronin.controller.add("default","Project", "Toggle Animation (experimental)",() => { ronin.commander.toggleAnimation(); },"CmdOrCtrl+Shift+T");
ronin.controller.add("default","Commander","Toggle",() => { ronin.commander.toggle(); },"CmdOrCtrl+K"); ronin.controller.add("default","Commander","Toggle",() => { ronin.commander.toggle(); },"CmdOrCtrl+K");
ronin.controller.commit(); ronin.controller.commit();
ronin.install(document.body); ronin.install(document.body);

View File

@ -4,6 +4,7 @@ function Commander (ronin) {
this._input = document.createElement('textarea') this._input = document.createElement('textarea')
this._status = document.createElement('div') this._status = document.createElement('div')
this._status.id = 'status' this._status.id = 'status'
this.isAnimated = false
this.install = function (host) { this.install = function (host) {
this.el.appendChild(this._input) this.el.appendChild(this._input)
@ -20,12 +21,18 @@ function Commander (ronin) {
this.hide() this.hide()
} }
this.run = function (txt = this._input.value) { this.run = (txt = this._input.value) => {
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return } if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
console.log('========') !this.isAnimated && console.log('========')
ronin.surface.maximize() ronin.surface.maximize()
const inter = new Lisp(txt, ronin.library) const inter = new Lisp(txt, ronin.library)
inter.toPixels() inter.toPixels()
this.isAnimated && requestAnimationFrame(() => this.run(txt))
}
this.toggleAnimation = () => {
this.isAnimated = !this.isAnimated
this.run(this._input.value)
} }
this.load = function (txt) { this.load = function (txt) {

View File

@ -253,4 +253,8 @@ function Library (ronin) {
} }
return a === b return a === b
} }
// Livecoding
this.time = Date.now
} }

10
examples/animation.lisp Normal file
View File

@ -0,0 +1,10 @@
; animation
; click Project > Toggle Animation
(
(def t (sin (div (time) 100)))
(def pos (add 200 (mul 30 t)))
(def square (lambda (a) (rect (add 200 a) a a a)))
(stroke (square pos) 1 "red")
)