Created
February 28, 2014 13:18
-
-
Save ds604/9270924 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
body, html { | |
height: 100%; | |
margin: 0; | |
} |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="description" content="Simple animation tests" /> | |
<meta charset=utf-8 /> | |
<title>Simple Animation Tests</title> | |
</head> | |
<body> | |
<canvas id="canvas"></canvas> | |
</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
var canvas = document.getElementById('canvas'), | |
ctx = canvas.getContext('2d'), | |
HEIGHT = 600, | |
WIDTH = 600, | |
TO_RADIANS = Math.PI / 360; | |
var raf = (function(){ | |
return window.requestAnimationFrame || | |
window.webkitRequestAnimationFrame || | |
window.mozRequestAnimationFrame || | |
window.oRequestAnimationFrame || | |
window.msRequestAnimationFrame || | |
function( callback ){ | |
window.setTimeout(callback, 1000 / 60); | |
}; | |
})(); | |
function clear(style) { | |
ctx.save(); | |
ctx.fillStyle = style || 'rgba(0,0,0,0.01)'; | |
ctx.fillRect(0, 0, WIDTH, HEIGHT); | |
ctx.restore(); | |
} | |
function square(x, y, w, h) { | |
ctx.beginPath(); | |
ctx.rect(WIDTH/2 + x, HEIGHT/2 + y, w, h); | |
ctx.closePath(); | |
ctx.fill(); | |
} | |
function circle(x, y, w, h) { | |
ctx.beginPath(); | |
ctx.arc(WIDTH/2 + x, HEIGHT/2+ y, w, 0, Math.PI*2, true); | |
ctx.closePath(); | |
ctx.fill(); | |
} | |
canvas.width = WIDTH; | |
canvas.height = HEIGHT; | |
var offsetX = 0, | |
offsetY = 0, | |
x_prev, | |
y_prev, | |
x = 0, | |
y = 0; | |
function draw() { | |
//clear(); | |
offsetX += Math.random() * 80; | |
offsetY += Math.E * 40; | |
x = Math.cos(WIDTH + offsetX * TO_RADIANS) * WIDTH/4; | |
y = Math.sin(HEIGHT + offsetY * TO_RADIANS) * HEIGHT/4; | |
ctx.fillStyle = 'cyan'; | |
//circle(x, y, 2, 10); | |
// offsetX += 2; | |
//draw line | |
ctx.lineWidth = 2; | |
ctx.strokeStyle = 'rgba(255,0,0,0.1)'; | |
ctx.beginPath(); | |
ctx.moveTo(x_prev,y_prev); | |
ctx.lineTo(WIDTH/2 + x,HEIGHT/2 + y); | |
ctx.stroke(); | |
x_prev = WIDTH/2 + x; | |
y_prev = HEIGHT/2 + y; | |
raf(draw, 16); | |
} | |
clear('black'); | |
draw(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment