Skip to content

Instantly share code, notes, and snippets.

@sanaerosen
Created December 14, 2013 21:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanaerosen/7964908 to your computer and use it in GitHub Desktop.
Save sanaerosen/7964908 to your computer and use it in GitHub Desktop.
<meta name="description" content="Blinkenlights" />
<html>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://blinken.eecs.umich.edu/client.js"></script>
<body></body>
</html>
(new Blinken()).run(function () {
var x = 0;
var d = 1;
var period = 11;
var slowdown = 5;
var range = function(x, period, start, end, i) {
var i_adjusted = mod(i - x, period);
if (i_adjusted > start && i_adjusted < end) {
return true;
}
return false;
};
var mod = function (n, m) {
return (n + m) % m;
};
// Update lights one frame
return function (lights) {
var y = x/slowdown;
for (i = 0; i < lights.length; i++) {
if (range(y, period, 2, 5, i)) {
lights[i].rgb(0, 1, 0);
} else if (range(y, period, 0,7, i)) {
lights[i].rgb(1, 0, 0);
} else {
lights[i].rgb(1, 1, 1);
}
}
x += d;
if (x == slowdown*period){
x = 0;
}
return 50; // ms until called again
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment