Created
April 27, 2013 21:17
-
-
Save jeremyckahn/5474761 to your computer and use it in GitHub Desktop.
An animation example from a tutoring session.
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> | |
| <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