Added (ronin) object, renamed animation function to .animate()

This commit is contained in:
Devine Lu Linvega 2019-07-17 09:21:17 +09:00
parent 6b77402544
commit 1a7b1c53d7
6 changed files with 39 additions and 26 deletions

View File

@ -46,7 +46,7 @@
ronin.controller.add("default","View","Toggle Commander",() => { ronin.commander.toggle(); },"CmdOrCtrl+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", "Toggle Animation (experimental)",() => { ronin.commander.toggleAnimation(); },"CmdOrCtrl+Shift+T");
ronin.controller.add("default","Project", "Toggle Animation (experimental)",() => { 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

@ -4,7 +4,6 @@ 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)
@ -23,16 +22,10 @@ function Commander (ronin) {
this.run = (txt = this._input.value) => {
if (txt.indexOf('$') > -1) { ronin.log('Present: $'); return }
!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)
ronin.always && requestAnimationFrame(() => this.run(txt))
}
this.load = function (txt) {

View File

@ -82,14 +82,14 @@ function Library (ronin) {
this._filter = (fn, arr) => {
return arr.filter(fn)
}
this.filter= (fn, arr) => {
const list = Array.from(arr);
return Promise.all(list.map((element, index) => fn(element, index, list)))
.then(result => {
return list.filter((_, index) => {
return result[index];
});
});
this.filter = (fn, arr) => {
const list = Array.from(arr)
return Promise.all(list.map((element, index) => fn(element, index, list)))
.then(result => {
return list.filter((_, index) => {
return result[index]
})
})
}
this.reduce = (fn, arr, acc = 0) => {
@ -193,7 +193,16 @@ function Library (ronin) {
return rect
}
//
this.get = (item, key) => {
return item[key]
}
this.set = (item, key, val) => {
item[key] = val
return item[key]
}
// TODO: Should remove (of) for (get)?
this.of = (h, ...keys) => {
return keys.reduce((acc, key) => {
@ -315,9 +324,11 @@ function Library (ronin) {
}
// Livecoding
this.time = Date.now
// javascript interop
this.js = window
// Client
this.ronin = ronin
}

View File

@ -21,6 +21,10 @@ function Ronin () {
this.surface = new Surface(this)
this.library = new Library(this)
// Parameters
this.always = false
this.install = function (host = document.body) {
this._wrapper = document.createElement('div')
this._wrapper.id = 'wrapper'
@ -56,6 +60,11 @@ function Ronin () {
}
this.animate = (b = true) => {
this.always = b
this.commander.run()
}
// Zoom
this.modZoom = function (mod = 0, set = false) {

View File

@ -123,11 +123,11 @@ function Surface (ronin) {
this.draw = function (img, rect = this.getFrame()) {
return new Promise(resolve => {
img.onload = () => {
ronin.log(`Draw ${img.width}x${img.height}`)
this.context.drawImage(img, rect.x, rect.y, rect.w, rect.h) // no strect: img.height * (rect.w / img.width)
resolve()
}
});
ronin.log(`Draw ${img.width}x${img.height}`)
this.context.drawImage(img, rect.x, rect.y, rect.w, rect.h) // no strect: img.height * (rect.w / img.width)
resolve()
}
})
}
this.crop = function (rect) {

View File

@ -1,7 +1,7 @@
; animation
; click Project > Toggle Animation
; animate
(
(ronin animate)
(def t (sin (div (time) 100)))
(def pos (add 200 (mul 30 t)))