-
-
Save rborn/ef1899a01ebb44c7149bd0d0c0087a0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var neopixelWrite = require('ESP8266').neopixelWrite; | |
var count = 120; | |
var pixels = new Uint8Array(count * 3); | |
function update() { | |
neopixelWrite(14, pixels); | |
} | |
function dampen(p) { | |
var i = (p % count) * 3; | |
pixels[i]>>>=1; | |
pixels[++i]>>>=1; | |
pixels[++i]>>>=1; | |
} | |
function rgb(p, r, g, b) { | |
var i = (p % count) * 3; | |
pixels[i] = g; | |
pixels[++i] = r; | |
pixels[++i] = b; | |
} | |
function hue(p, h, d) { | |
h = h % 768; | |
d = d || 0; | |
if (h < 256) return rgb(p, h >> d, (255-h) >> d, 0); | |
if (h < 512) return rgb(p, (511-h)>>d,0,(h-256)>>d); | |
return rgb(p, 0, (h-512)>>d, (767-h)>>d); | |
} | |
function rand(x) { | |
return Math.floor(Math.random() * x); | |
} | |
var bugs = []; | |
function Bug() { | |
var p, h, l, d; | |
function init() { | |
p = rand(count); | |
h = rand(768); | |
l = rand(50) + 50; | |
d = rand(2) * 2 - 1; | |
} | |
function update() { | |
for (var i = 0; i < 6; i++) { | |
dampen(p + count - i); | |
} | |
p = (p + d + count) % count; | |
hue(p, h, 2); | |
h =(h + 1) % 768; | |
if (!(--l)) { | |
for (i = 1; i < 16; i++) { | |
h += 27; | |
hue(p + i, h, i >> 1); | |
hue(p + count - i, h, i >> 1); | |
} | |
init(); | |
} | |
} | |
init(); | |
bugs.push(update); | |
} | |
for (var i = 0; i < 5; i++) Bug(); | |
var x = 0; | |
setInterval(function () { | |
for (var i = 0; i < 2; i++) { | |
x = (x + 1) % bugs.length; | |
bugs[x](); | |
} | |
update(); | |
}, 33); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment