-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
122 lines (89 loc) · 2.14 KB
/
app.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
var app = require('http').createServer();
var io = require('socket.io').listen(app);
app.listen(8081, '127.0.0.1');
io.sockets.on('connection', connected);
io.set('log level', 1);
function setLights(data) {
//console.log(data);
for (var i = 0; i < 333; ++i) {
fn.light(i).setColor(data[i].r, data[i].g, data[i].b);
lightsLive[i] = {
r: data[i].r,
g: data[i].g,
b: data[i].b
};
}
io.sockets.emit('update', lightsLive);
fn.flush();
}
function connected(socket) {
socket.emit('welcome', {});
socket.on('update', setLights);
}
var fn = require('fountain').FountainClass.createFountain();
sim = fn;
function rgbToHex(r, g, b) {
r = r.toString(16);
g = g.toString(16);
b = b.toString(16);
if (r.length == 1) r = '0' + r;
if (g.length == 1) g = '0' + g;
if (b.length == 1) b = '0' + b;
return (r + g + b).toUpperCase();
}
_color = function(r, g, b, a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
if (!a) {
a = 100;
}
this.realValue = {
r: r,
g: g,
b: b
};
this.toRgba = function() {
return rgbToHex(r, g, b);
};
};
function array_value(arr, key) {
return arr[key];
}
function rangeSimple(start, end) {
var arr = [];
for (var i = start; i < end; i++) {
arr.push(i);
}
return arr;
}
var makeColor = function(r, g, b, a) {
if (!a) {
a = 100;
}
return new _color(r, g, b, a);
};
function range(start, end) {
var arr = new Array();
for (var i = start; i < end; i++) {
arr[i] = parseInt(i);
}
return arr;
}
function rangeReverse(start, end) {
var arr = new Array();
for (var i = end; i >= start; i--) {
arr[end - i] = i;
}
return arr;
}
var lights = [];
var lightsLive = [];
function reset() {
for (var i = 0; i < 333; ++i) {
fn.light(i).setColor(0, 0, 0);
}
fn.flush();
}
//fn.evalFile(__dirname+'/shows/Night_Souls/js/show.js');