Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
If you hadn't already noticed, there are effectively no boundaries to the examples used so far. What I mean by this is that nothing happens when a shape animates up to the edge of the canvas; it just disappears, never to be seen again. This may be the effect that you're after; for example, if you're only creating a short animation that stops long before you reach an edge, or if you want to animate a shape over the edge of the canvas. But, what if you don't want this behavior? What if you want shapes to be aware of their surroundings, by perhaps bouncing off the edges and reversing their direction? This is a behavior that changes an animation from something quite linear and scripted, to something more natural and unpredictable.
Before you start learning how to achieve this behavior, prepare the code using techniques learned from this chapter: