Created
December 14, 2013 21:06
-
-
Save sanaerosen/7964908 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
<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> |
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
(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