<html>
<head>
<meta charset=utf-8 />
<title>JSBin 5th bday!</title>
<style>
body {
text-align: center;
}
canvas {
position: absolute;
top: 100px;
left: 0%;
}
</style>
</head>
<body>
<canvas id="c" width="600" height="600"></canvas>
<canvas id="c2" width="600" height="600"></canvas>
</body>
</html>
/*
For JSBin 5th birthday compo
Author: Kushagra Gour (@chinchang457)
*/
var PI_BY_180 = Math.PI / 180,
PI2 = 2 * Math.PI,
c = document.querySelector('#c'),
ctx = c.getContext('2d'),
c2 = document.querySelector('#c2'),
ctx2 = c2.getContext('2d'),
dots = [],
radius = 20;
function Dot (cx, cy, angle) {
this.cx = cx;
this.cy = cy;
this.angle = angle;
}
Dot.prototype.draw = function () {
ctx.beginPath();
ctx.arc(this.x, this.y, 3, 0, 2 * Math.PI, false);
ctx.fillStyle = 'black';
ctx.fill();
return this;
};
Dot.prototype.update = function () {
this.angle += 3;
this.x = this.cx + radius * Math.cos(this.angle * PI_BY_180);
this.y = this.cy + radius * Math.sin(this.angle * PI_BY_180);
return this;
};
function animate() {
ctx.clearRect (0, 0, 600, 600);
ctx.save();
ctx.translate(50, 50);
for (var i = 0; i < dots.length; i++) {
dots[i].update();
dots[i].draw();
}
ctx.restore();
requestAnimationFrame(animate);
}
for (var i = 0; i < 20; i++) {
for (var j = 0; j < 20; j++) {
var cx = i * 23,
cy = j * 23;
// draw circles in bg canvas
ctx2.save();
ctx2.translate(50, 50);
ctx2.strokeStyle = "#333";
ctx2.beginPath();
ctx2.arc(cx, cy, radius, 0, PI2, false);
ctx2.stroke();
ctx2.restore();
// draw the dots
var d = new Dot(cx, cy, i * 20 + j * 20);
dots.push(d);
}
}
animate();
Output
300px
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. |