-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatterns.js
More file actions
61 lines (53 loc) · 2.07 KB
/
patterns.js
File metadata and controls
61 lines (53 loc) · 2.07 KB
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
var tinycolor = require("tinycolor2");
module.exports = {
patterns: [RainbowBeatPattern]
};
function BasePattern(pixelpusher, bpminfo) {
this.pixelpusher = pixelpusher;
this.bpminfo = bpminfo;
this.patternData = {};
}
BasePattern.prototype.tick = function tick(ms_since) {
};
function RainbowBeatPattern(pixelpusher, bpminfo) {
BasePattern.call(this, pixelpusher, bpminfo);
this.HUE_INCR_PER_MS = 0.005;
}
RainbowBeatPattern.prototype.tick = function tick(ms_since) {
var rendered = [];
var pulseval = this.bpminfo.pulse();
if (pulseval < 0.2) {
pulseval = 0.2;
}
Object.keys(pixelpusher.controllers).forEach(function (key) {
var controller = pixelpusher.controllers[key];
var NUM_STRIPS = controller.params.pixelpusher.numberStrips;
var PIXELS_PER_STRIP = controller.params.pixelpusher.pixelsPerStrip;
var strips = [];
for (var stripNum = 0; stripNum < PIXELS_PER_STRIP; stripNum++) {
strips.push(new PixelStrip(stripNum, PIXELS_PER_STRIP));
}
for (var stripId = 0; stripId < NUM_STRIPS; stripId++) {
var s = strips[stripId];
for (var i = 0; i < PIXELS_PER_STRIP; i++) {
var rgb = tinycolor.fromRatio({
h: (((i + this.patternData.index) % PIXELS_PER_STRIP) / PIXELS_PER_STRIP),
s: 1 - pulseval,
l: .51
}).toRgb();
s.getPixel(i).setColor(rgb.r, rgb.g, rgb.b, 255);
}
// render the strip data into the correct format for sending
// to the pixel pusher controller
// add this data to our list of strip data to send
rendered.push(s.getStripData());
}
// inform the controller of the new strip frame
controller.refresh(rendered);
this.patternData.index += this.HUE_INCR_PER_MS * ms_since;
if (this.patternData.index > PIXELS_PER_STRIP) {
this.patternData.index = 0;
}
});
};
RainbowBeatPattern.prototype = Object.create(BasePattern.prototype);