Merge pull request #2 from bluemaex/master
add generic callback for animations #ohm2013
This commit is contained in:
commit
416260c4fe
3 changed files with 38 additions and 9 deletions
5
anim.js
5
anim.js
|
@ -1,8 +1,7 @@
|
|||
var ease = require('./easing.js').ease
|
||||
var resolution = 25;
|
||||
|
||||
exports.Anim = function(universe) {
|
||||
this.universe = universe;
|
||||
exports.Anim = function() {
|
||||
this.fx_stack = [];
|
||||
this.add = function(to, duration, options) {
|
||||
var options = options || {};
|
||||
|
@ -14,7 +13,7 @@ exports.Anim = function(universe) {
|
|||
this.delay = function(duration) {
|
||||
return this.add({}, duration);
|
||||
}
|
||||
this.run = function(onFinish) {
|
||||
this.run = function(universe, onFinish) {
|
||||
var config = {}
|
||||
, t = 0
|
||||
, d = 0
|
||||
|
|
8
test.js
8
test.js
|
@ -43,7 +43,7 @@ green_water(universe, [3+15, 6+15, 9+15], 4000);
|
|||
|
||||
return;
|
||||
|
||||
var x = new A(universe)
|
||||
var x = new A()
|
||||
.add({1: 255, 6: 110, 7: 255, 8: 10}, 1200)
|
||||
.delay(1000)
|
||||
.add({1: 0}, 600)
|
||||
|
@ -71,8 +71,8 @@ var x = new A(universe)
|
|||
.delay(200)
|
||||
.add({2: 0});
|
||||
|
||||
var y = new A(universe)
|
||||
var y = new A()
|
||||
.add({9: 255}, 10000);
|
||||
|
||||
x.run(done);
|
||||
y.run(done);
|
||||
x.run(universe, done);
|
||||
y.run(universe, done);
|
34
web.js
34
web.js
|
@ -1,7 +1,8 @@
|
|||
var http = require('http'),
|
||||
path = require('path'),
|
||||
io = require('socket.io'),
|
||||
fs = require('fs')
|
||||
fs = require('fs'),
|
||||
A = require('./anim.js').Anim
|
||||
;
|
||||
|
||||
exports.init = function(dmx) {
|
||||
|
@ -13,7 +14,36 @@ exports.init = function(dmx) {
|
|||
});
|
||||
|
||||
request.on("end", function () {
|
||||
var filePath = '.' + request.url;
|
||||
var urlData = require('url').parse(request.url),
|
||||
urlPath = urlData.pathname.split('/');
|
||||
|
||||
if(urlPath.length == 3 && urlPath[1] == 'animation') {
|
||||
try {
|
||||
// save old states
|
||||
var universe = dmx.drivers[urlPath[2]], old = {}, black = {};
|
||||
for(var i = 0; i < 256; i++) {
|
||||
old[i] = universe.get(i);
|
||||
black[i] = 0;
|
||||
}
|
||||
|
||||
var jsonAnim = JSON.parse(reqBody), animation = new A();
|
||||
for(var step in jsonAnim) {
|
||||
animation.add(jsonAnim[step].to, jsonAnim[step].duration || 0, jsonAnim[step].options || {});
|
||||
}
|
||||
|
||||
animation.add(old, 0);
|
||||
animation.run(universe);
|
||||
response.write('{ "success": true }');
|
||||
} catch(e) {
|
||||
response.write('{ "error": "broken json" }');
|
||||
}
|
||||
|
||||
response.end();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var filePath = '.' + urlData.pathname;
|
||||
if (filePath == './')
|
||||
filePath = './index.html';
|
||||
|
||||
|
|
Loading…
Reference in a new issue