-
Notifications
You must be signed in to change notification settings - Fork 0
/
orb.js
53 lines (51 loc) · 1.29 KB
/
orb.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var interval = null;
var activeFunction = null;
var activeFunctionName = null;
// user controllable data
var data = {
red: 255,
blue: 255,
green: 0,
period: 10000,
intensity: 1.0,
pattern: null,
};
module.exports = function(model,client){
return {
update: function(d){
// only allow updating the color field for now
data.red = Math.min(Math.max(d.red,0),255);
data.blue = Math.min(Math.max(d.blue,0),255);
data.green = Math.min(Math.max(d.green,0),255);
data.period = d.period;
data.intensity = Math.min(Math.max(d.intensity,0.0),1.0);
},
data: function(){
return data;
},
isRunning: function(){ return interval != null; },
run: function(name, fn){
return run(name,fn,model,client,data);
},
pause: function(){
return clearInterval(interval);
},
unpause: function(){
if (activeFunction) {
return run(activeFunctionName, activeFunction, model, client, data);
}
},
stop: function(){
return run(null, function(m,c){
c.mapParticles([],m);
}, model, client);
},
};
}
function run(name, fn, model, client){
data.pattern = name;
activeFunctionName = name;
activeFunction = fn;
clearInterval(interval);
interval = setInterval(fn, 10, model, client, data);
}