Created
April 3, 2012 13:57
-
-
Save herschel666/2292219 to your computer and use it in GitHub Desktop.
Follow the Cursor
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
canvas { | |
margin: 40px; | |
border: 1px solid #999; | |
} |
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 charset="utf-8" /> | |
<title>Follow the Cursor</title> | |
<link rel="stylesheet" href="follow_the_cursor.css" /> | |
</head> | |
<body> | |
<canvas id="cnvs" width="400" height="400"></canvas> | |
<script src="follow_the_cursor.js"></script> | |
</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 cnvs = document.getElementById('cnvs'); | |
var pos_x = 0; | |
var pos_y = 0; | |
var ctx = cnvs.getContext('2d'); | |
function draw(x, y) { | |
ctx.fillStyle = 'rgba(255,255,255,.3)'; | |
ctx.fillRect(0,0,399,399); | |
ctx.fillStyle = '#111'; | |
ctx.beginPath(); | |
ctx.moveTo(x, y); | |
ctx.arc(x,y,10,0,Math.PI*2,true); | |
ctx.closePath(); | |
ctx.fill(); | |
} | |
function animate() { | |
setTimeout(animate, 1000/60); | |
cnvs.addEventListener('mousemove', function (evnt) { | |
pos_x = evnt.offsetX; | |
pos_y = evnt.offsetY; | |
}, true); | |
draw(pos_x, pos_y); | |
} | |
animate(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment