November 2011
Intermediate to advanced
348 pages
7h 2m
English
In this recipe, we'll explore the third major type of motion—oscillation. Some good examples of oscillations are a bouncing weight attached to a spring, an oscillating bubble, or a pendulum that swings back and forth.

Follow these steps to oscillate a box back and forth:
Animation class:<head>
<script src="animation.js">
</script>Animation object and get the canvas context: <script>
window.onload = function(){
var anim = new Animation("myCanvas");
var canvas = anim.getCanvas();
var context = anim.getContext();box object that contains the box's position and size: var box = {Read now
Unlock full access