Created
December 14, 2013 21:15
-
-
Save sanaerosen/7964982 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 start_inner = 2; | |
var start_outer = 0; | |
var end_inner = 5; | |
var end_outer = 7; | |
var range = function(x, period, start, end, i) { | |
var i_adjusted = (i - x) % period; | |
if (i_adjusted > start && i_adjusted < end) { | |
return true; | |
} | |
return false; | |
}; | |
// Update lights one frame | |
return function (lights) { | |
for (i = 0; i < lights.length; i++) { | |
if (range(x, period, start_inner, end_inner, i)) { | |
lights[i].rgb(0, 1, 0); | |
} else if (range(x, period, start_outer, end_outer, i)) { | |
lights[i].rgb(1, 0, 0); | |
} else { | |
lights[i].rgb(1, 1, 1); | |
} | |
} | |
x += d; | |
if (x == period){ | |
x = 0; | |
} | |
return 150; // ms until called again | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment