Last active
September 6, 2021 22:24
-
-
Save creationix/62cc67b7d7c3fbe57bba691028d79d56 to your computer and use it in GitHub Desktop.
This file contains 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 Neopixel = require('neopixel'); | |
var data = new Uint8Array(4*12); | |
function hue(p, h, l) { | |
h = h % 0x600; | |
var r, g, b; | |
if (h < 0x100) { r = 0xff; g = h; b = 0; } | |
else if (h < 0x200) { r = 0x1ff - h; g = 0xff; b = 0; } | |
else if (h < 0x300) { r = 0; g = 0xff; b = h - 0x200; } | |
else if (h < 0x400) { r = 0; g = 0x3ff - h; b = 0xff; } | |
else if (h < 0x500) { r = h - 0x400; g = 0; b = 0xff; } | |
else { r = 0xff; g = 0; b = 0x5ff - h; } | |
return rgb(p, (r*l) >> 8, (g*l)>>8, (b*l)>>8); | |
} | |
function rgb(p, r, g, b,w) { | |
var i = p * 4; | |
data[i++] = g|0; | |
data[i++] = r|0; | |
data[i++] = b|0; | |
data[i++] = w|0; | |
} | |
var h = 0; | |
setInterval(function () { | |
for (var p = 0; p < 16; p++) { | |
hue(p, p*128 + h,64); | |
} | |
h += 42; | |
Neopixel.write(D4, data); | |
}, 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment