HTML and CSS Reference
In-Depth Information
</body>
</html>
Now, when you execute Example 5-7 ( CH5EX7.html ), you will see a bunch of balls of
the same size and mass bumping off of each other and the walls of the canvas, as shown
in Figure 5-10 . When you look at this demo, imagine all the ways you could modify it
to do different things. You could create balls with different masses and different speeds,
or even create balls that don't move but simply alter the direction of other balls that
hit them. In Example 5-8 , we will take a slightly different look at this same code and
add some new properties to make it more interesting.
Figure 5-10. Balls of the same size bouncing off one another
Multiple Balls Bouncing with Friction
If we want the balls to slow down and eventually stop, we need to add friction to
Example 5-7 . For our purposes, simple friction is a value we use to modify the velocity
of our objects every time they are drawn to the canvas.
 
Search WWH ::




Custom Search