Skip to content

Instantly share code, notes, and snippets.

@jeremyckahn
Created April 27, 2013 21:17
Show Gist options
  • Select an option

  • Save jeremyckahn/5474761 to your computer and use it in GitHub Desktop.

Select an option

Save jeremyckahn/5474761 to your computer and use it in GitHub Desktop.
An animation example from a tutoring session.
<!DOCTYPE>
<html>
<head>
</head>
<body>
<canvas style="height: 400px; width: 400px; border: solid 1px #000;"></canvas>
<script>
var color = '#f0f';
var radius = 50;
function circle (canvas_context, x, y) {
canvas_context.beginPath();
canvas_context.arc(x, y, radius, 0, Math.PI*2, true);
canvas_context.fillStyle = color;
canvas_context.fill();
canvas_context.closePath();
}
var canvas = document.querySelector('canvas');
canvas.width = 400;
canvas.height = 400;
var ctx = canvas.getContext('2d');
var x = 0;
var y = 0;
function update () {
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
webkitRequestAnimationFrame(update);
canvas.width = canvas.width;
x++;
y++;
circle(ctx, x, y);
}
update();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment