-
-
Save rebaomi/8385492 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 hidden or 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 = window.innerHeight, | |
WIDTH = window.innerWidth, | |
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 ||'black'|| '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; | |
function draw(){ | |
clear(); | |
offsetX += 1 ; | |
offsetY++; | |
var x = Math.cos(WIDTH + offsetX * TO_RADIANS)*WIDTH/7; | |
var y = Math.cos(HEIGHT + offsetY * TO_RADIANS)*HEIGHT/2; | |
ctx.fillStyle = 'orange'; | |
circle(x,y,offsetX/200,offsetY); | |
circle(y,x,offsetX/200,offsetY); | |
circle(x,x,offsetX/200,offsetY); | |
circle(y,y,offsetX/200,offsetY); | |
//circle(x, y, 2, 10); | |
// square(x,y,5,10); | |
if(offsetX>1000){offsetX=0;} | |
raf(draw,16); | |
} | |
clear('black'); | |
draw(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment