Skip to content

Instantly share code, notes, and snippets.

@devyn
Created November 12, 2009 06:50
Show Gist options
  • Save devyn/232667 to your computer and use it in GitHub Desktop.
Save devyn/232667 to your computer and use it in GitHub Desktop.
<!-- WORKS!!! -->
<html>
<head>
<title>FaceMouse</title>
<script src="canvas-animation.js"></script>
<script>
var anim;
var mousex = 0;
var mousey = 0;
function init() {
anim = new Animation('canvas', 45);
document.onmousemove = function(e) { mousex = e.pageX; mousey = e.pageY; };
anim.drawing.circle = function(ctx, frame) {
ctx.save();
ctx.translate(40,40);
ctx.rotate(Math.atan2(mousex - 40, mousey - 40)*-1);
ctx.fillStyle = "#000000";
ctx.beginPath();
ctx.arc(0,0,20,0,Math.PI*2,false);
ctx.fill();
ctx.strokeStyle="#ffffff";
ctx.beginPath();
ctx.moveTo(0,0);
ctx.lineTo(0,20);
ctx.stroke();
ctx.restore();
};
}
</script>
</head>
<body onload="init();">
<canvas id="canvas"></canvas>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment