HTML and CSS Reference
In-Depth Information
Chapter 12
Particle Attraction and Gravity
What we'll cover in this chapter:
Particles
Gravity
Springs
During the progression of this topic, each chapter has added a new concept to enhance the motion quality
of our animations. At first, you just had things moving around. Then things started interacting with the
environment, then with the user, and then with each other through collisions. In this chapter, we expand on
the ways objects interact with each other, particularly from a distance. Specifically, we cover particles,
gravity (a little differently this time), springs (again!), and have them all interact with each other.
Particles
For the purposes of this chapter, a particle is simply a single unit, generally in the company of several (or
many) other similar units. For example, a particle can be a marble, a balloon, or a planet.
Particles generally share a common type of behavior, but also can have their own individuality. In the topic
examples, you've already seen this when using instances of the Ball class. Each object has its own
properties: velocity, mass, size, color, etc., but all of the balls move using the same rules.
In this chapter, you again use the Ball class, because it already has the functionality you need here. The
particle object holds only properties, and the rest of the script takes care of moving each particle. Another
strategy is to define a move method in the particle class, so each object takes responsibility for moving
 
Search WWH ::




Custom Search