<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({title: "Overtaken",
author: "odious_toad"})).run(function () {
// configuration! numConcurrent must be at least 1
var numConcurrent = 5;
var numSpacesBetweenStarts = 5;
// whether or not to randomly generate brightness
// looks better without
var brightness = false;
function RGBA(r, g, b, a) {
this.r = r;
this.g = g;
this.b = b;
this.a = a;
}
function getRandomColor() {
return new RGBA(Math.random(), Math.random(), Math.random(), Math.random());
}
// between 2 and -2
function getGrowth() {
var tmp = Math.random();
var abs = (tmp < 0.33) ? 2 : ((tmp > 0.44) ? 1 : 0);
return (Math.random() < 0.66) ? abs : abs * -1;
}
function setExpandingColor(rgba, maxI, lights) {
var halfLength = lights.length / 2;
for (var i = 0; i < maxI && i < halfLength; i++) {
var up = halfLength+i;
var down = halfLength-1-i;
lights[up].rgb(rgba.r, rgba.g, rgba.b);
lights[down].rgb(rgba.r, rgba.g, rgba.b);
lights[up].a = brightness ? Math.random() : rgba.a;
lights[down].a = brightness ? Math.random() : rgba.a;
}
}
// initialization
var currentDistance = [];
var going = [];
var currentColors = [];
for (var i = 0; i < numConcurrent; i++) {
currentDistance.push(0);
going.push(false);
currentColors.push(getRandomColor());
}
// set the first color to start
going[0] = true;
// make an extra space for the background color
currentColors.push(getRandomColor());
// make first background color black (background color lives at the end)
currentColors[numConcurrent].a = 0;
// update lights one frame
return function (lights) {
// set background color
setExpandingColor(currentColors[numConcurrent], lights.length / 2, lights);
// set other colors
for (var i = 0; i < numConcurrent; i++) {
if (i > 0 && currentDistance[i-1] > numSpacesBetweenStarts) {
going[i] = true;
}
if (going[i]) {
setExpandingColor(currentColors[i], currentDistance[i], lights);
currentDistance[i] = Math.abs(currentDistance[i] + getGrowth());
}
}
// the first one can be overtaken, and if it has we should move on.
var moveNext = false;
for (var i = 0; i < numConcurrent; i++) {
if (currentDistance[i] >= lights.length / 2) {
moveNext = true;
}
}
// move everything for the next iteration
if (moveNext) {
// promote the first color to background
currentColors[numConcurrent] = currentColors[0];
// move existing colors over
for (var i = 0; i < numConcurrent-1; i++) {
currentColors[i] = currentColors[i+1];
currentDistance[i] = currentDistance[i+1];
going[i] = going[i+1];
}
// pick a new color and reset variables
currentColors[numConcurrent-1] = getRandomColor();
currentDistance[numConcurrent-1] = 0;
going[numConcurrent-1] = false; going[0] = true;
}
return 100;
};
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |