diff --git a/desktop/sources/index.html b/desktop/sources/index.html index a775c71..1b36e48 100644 --- a/desktop/sources/index.html +++ b/desktop/sources/index.html @@ -42,6 +42,7 @@ ronin.controller.addRole('default', 'Edit', 'selectall') 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", "Toggle Animation (experimental)",() => { ronin.commander.toggleAnimation(); },"CmdOrCtrl+Shift+T"); ronin.controller.add("default","Commander","Toggle",() => { ronin.commander.toggle(); },"CmdOrCtrl+K"); ronin.controller.commit(); ronin.install(document.body); diff --git a/desktop/sources/scripts/commander.js b/desktop/sources/scripts/commander.js index 0ace1ff..b6b5b3d 100644 --- a/desktop/sources/scripts/commander.js +++ b/desktop/sources/scripts/commander.js @@ -4,6 +4,7 @@ function Commander (ronin) { this._input = document.createElement('textarea') this._status = document.createElement('div') this._status.id = 'status' + this.isAnimated = false this.install = function (host) { this.el.appendChild(this._input) @@ -20,12 +21,18 @@ function Commander (ronin) { this.hide() } - this.run = function (txt = this._input.value) { + this.run = (txt = this._input.value) => { if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return } - console.log('========') + !this.isAnimated && console.log('========') ronin.surface.maximize() const inter = new Lisp(txt, ronin.library) inter.toPixels() + this.isAnimated && requestAnimationFrame(() => this.run(txt)) + } + + this.toggleAnimation = () => { + this.isAnimated = !this.isAnimated + this.run(this._input.value) } this.load = function (txt) { diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index f3bc7fa..53f0f0d 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -253,4 +253,8 @@ function Library (ronin) { } return a === b } + + // Livecoding + + this.time = Date.now } diff --git a/examples/animation.lisp b/examples/animation.lisp new file mode 100644 index 0000000..1a7d77a --- /dev/null +++ b/examples/animation.lisp @@ -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") +) \ No newline at end of file