12
1
2
<html>
3
<head>
4
<meta name="description" content="Simple animation tests" />
5
<meta charset=utf-8 />
6
<title>Simple Animation Tests</title>
7
</head>
8
<body>
9
<canvas id="canvas"></canvas>
10
</body>
11
</html>
12
4
1
body, html {
2
height: 100%;
3
margin: 0;
4
}
62
1
var canvas = document.getElementById('canvas'),
2
ctx = canvas.getContext('2d'),
3
HEIGHT = window.innerHeight,
4
WIDTH = window.innerWidth,
5
TO_RADIANS = Math.PI / 360;
6
7
var raf = (function(){
8
return window.requestAnimationFrame ||
9
window.webkitRequestAnimationFrame ||
10
window.mozRequestAnimationFrame ||
11
window.oRequestAnimationFrame ||
12
window.msRequestAnimationFrame ||
13
function( callback ){
14
window.setTimeout(callback, 1000 / 60);
15
};
16
})();
17
18
function clear(style) {
19
ctx.save();
20
ctx.fillStyle = style || 'rgba(0,0,0,0.01)';
21
ctx.fillRect(0, 0, WIDTH, HEIGHT);
22
ctx.restore();
23
}
24
25
function square(x, y, w, h) {
26
ctx.beginPath();
27
ctx.rect(WIDTH/2 + x, HEIGHT/2 + y, w, h);
28
ctx.closePath();
29
ctx.fill();
30
}
31
32
function circle(x, y, w, h) {
33
ctx.beginPath();
34
ctx.arc(WIDTH/2 + x, HEIGHT/2+ y, w, 0, Math.PI*2, true);
35
ctx.closePath();
36
ctx.fill();
37
}
38
39
canvas.width = WIDTH;
40
canvas.height = HEIGHT;
41
42
var offsetX = 0,
43
offsetY = 0;
44
45
function draw() {
46
clear();
47
48
offsetX+= 2;
49
offsetY++;
50
var x = Math.sin(WIDTH + offsetX * TO_RADIANS) * WIDTH/4;
51
var y = Math.sin(HEIGHT + offsetY * TO_RADIANS) * HEIGHT/4;
52
53
ctx.fillStyle = 'cyan';
54
circle(x, y, 2, 10);
55
// offsetX += 2;
56
57
58
raf(draw, 16);
59
}
60
61
clear('black');
62
draw();
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. |