<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
</body>
</html>
var boomboom = (function() {
//Clear any existing page
document.getElementsByTagName("body")[0].innerHTML="";
var space=document.createElement("div");
var iterator=0;
var stars = 50;
var timer=100;
//Set container
space.setAttribute("id","space");
space.setAttribute("style","width:1000px;height:600px;margin:auto;border:solid 1px #000;position:relative;overflow:hidden;background:#000;color:#fff");
document.getElementsByTagName("body")[0].appendChild(space);
//Set interval and draw...
var interval = setInterval(function(){ drawStars(iterator,stars); }, timer);
drawStars(iterator, stars);
function drawStars(r,c) {
clearInterval(interval);
//a container for this set of stars
var starContainer=document.createElement("div");
//don't draw more if there are too many, it's got to go
if(iterator < 1000) {
for(var i = 0; i < c; i++) {
var x,y;
if(iterator < 100) {
x=500 + r * Math.cos(2 * Math.PI * i / c) * 0.7;
y=300 + r * Math.sin(2 * Math.PI * i / c) * 0.7;
}
//add some randomness for the boom boom
if(iterator > 100) {
x=500 + r * Math.cos(2 * Math.PI * i / c) * 0.7*Math.random();
y=300 + r * Math.sin(2 * Math.PI * i / c) * 0.7*Math.random();
}
//Make a star
var star=document.createElement("div");
star.setAttribute("class","star");
//Exploding stars are red, I hope
var color = iterator < 100 ? "color:#fff" : "color:rgb("+parseInt(255*Math.random())+",0,0)";
star.setAttribute("style","position:absolute; left:"+ x +"px;top:"+ y +"px;"+color);
//Change the star character as boom boom gets bigger
if(iterator <= 200) {
star.textContent="*";
}
else if(iterator >=200 & iterator <= 400) {
star.textContent="O";
}
else {
star.textContent="-";
}
//Add the star to its container
starContainer.appendChild(star);
}
}
//draw the container
space.appendChild(starContainer);
//increment the iterator. It's an iterator because we're using intervals and it's late.
iterator+=5;
//remove stars when we get too many
if(iterator > 200) {
space.removeChild(space.firstChild);
}
if(iterator < 1500) { //do it all again
timer = timer > 10 ? timer-10 : timer;
interval=setInterval(function(){ drawStars(iterator,stars); }, timer);
}
//make sure it's actually empty
else {
space.innerHTML="";
}
}
}());
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. |