Created
May 11, 2017 21:20
-
-
Save creationix/1dcfceb2a255547f3ea6988cd62aaa81 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
SPI2.setup({baud:3200000,mosi:B15}); | |
var count = 150; | |
var pixels = new Uint8Array(count * 3); | |
function update() { | |
SPI2.send4bit(pixels, 0b0001, 0b0011); | |
} | |
function dampen(p) { | |
var i = (p % count) * 3; | |
pixels[i]>>>=1; | |
pixels[++i]>>>=1; | |
pixels[++i]>>>=1; | |
pixels[++i]>>>=1; | |
} | |
function rgb(p, r, g, b, w) { | |
var i = (p % count) * 3; | |
pixels[i] = g; | |
pixels[++i] = r; | |
pixels[++i] = b; | |
// pixels[++i] = w; | |
} | |
function hue(p, h, d) { | |
h = (h + count) % 768; | |
d = d || 0; | |
if (h < 256) return rgb(p, h >> d, (255-h) >> d, 0, 0); | |
if (h < 512) return rgb(p, (511-h)>>d,0,(h-256)>>d, 0); | |
return rgb(p, 0, (h-512)>>d, (767-h)>>d, 0); | |
} | |
function rand(x) { | |
return Math.floor(Math.random() * x); | |
} | |
var h = 0; | |
it = setInterval(function () { | |
for (var p = 0; p < 150; p++) { | |
hue(p, h + p * 13, 5); | |
} | |
h = (h + 7) % 768; | |
update(); | |
}, 33); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment