Java Reference
In-Depth Information
The actual direction in which the Particle will travel is determined in the code in Listing 2-11 by
adding the attribute direction to a random value based on directionVariation . Once the final direction
is calculated, the deltaX and deltaY values are calculated as before.
Using the values above, the Particles will travel mostly straight up, with deviations of up to 10
degrees both clockwise and counterclockwise.
Example 7: Nonlinear Paths
A particle's path is as interesting as how the particle looks. This example explores a particle system
where the particles travel as if pulled by gravity. This is accomplished by changing the amount each
particle moves in the Y direction on each step.
Utilizing a new star shaped particle, a very festive effect can be created. The screenshot in
Figure 2-10 shows how the particles are first shot into the air and then fall. What is not evident from a
still shot is the parabolic curve each particle follows. This causes the particle to accelerate downward.
The code in Listing 2-12 shows how this is implemented.
Figure 2-10. Example 7, falling stars
Search WWH ::




Custom Search