Last active
April 21, 2017 09:22
-
-
Save benfoxall/9adbda6dc88929b99d2179d0515a82b5 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 rgb = new Uint8ClampedArray(50 * 3); | |
// Set the colours of a particular light (i) at a given intensity (s) | |
function set(r, g, b, i, s){ | |
i *= 3; | |
if(i > 0) { | |
rgb[i] = rgb[i] + ((r - rgb[i]) * s); i++; | |
rgb[i] = rgb[i] + ((g - rgb[i]) * s); i++; | |
rgb[i] = rgb[i] + ((b - rgb[i]) * s); i++; | |
} | |
} | |
// Flood the LEDs with a particular colour | |
function flood(r,g,b,cb) { | |
var p = 0; // the current position of the animation | |
var s = 8; // the number of steps it takes to fully change colour | |
var interval = setInterval(function() { | |
p++; | |
// this is the key/cool bit - needs a diagram | |
for(var i = 0; i < s; i++) { | |
set(r, g, b, p-i, 1/(s-i)); | |
} | |
require("neopixel").write(D1, rgb); | |
if((p-s) == rgb.length/3) { | |
clearInterval(interval); | |
console.log("cleared"); | |
if(cb) cb(); | |
} | |
}, 50); | |
} | |
flood(255,0,0,function(){ | |
flood(0, 255,150,function(){ | |
flood(0,0,0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment