Now let's implement StepAndDraw. As the name suggests, this procedure is called on every time step which means we first must update the velocity and position (based on the constant acceleration as well as initial velocity and position). Instantaneous final velocity (
) and displacement (
) are given by the following:
The velocity formula is fairly obvious. Since acceleration is in distance units per second per second and velocity is in distance units per second we simply need to multiply the size of the time step (
) by the constant acceleration (
) and add that to the inital velocity (
). The displacement formula is a little more complex. The first two terms are fairly obvious (taking initial position
and adding to it the change in position given by
or velocity times some amount of time which of course gives distance traveled). The
accounts for the change in velocity due to constant acceleration that occurs within the time step. Its origin is clear if you know calculus (the mathematics of continuous change), but we will not derive it here. In fact, the term
is basically inconsequential here because we assume a frame rate of 30 frames per second which means each time step is 1/30 of a second.
which is so small that the entire term
is dwarfed by
. Thus, we can omit it entirely. Not only does this simplify the code, it also makes it faster since there is one less term to compute. So in pseudocode, we have something like this as our updates for position and velocity:
Implement these formulas now. When you multiply the time step, think of a way we can write the code to make it more computationally efficient (remember that divisions are expensive).
Finally, draw the flare given the flare's position, hue, and intensity. Remember that the Flare procedure is defined in FTFlareGraphics as Flare(X,Y,Hue,Intensity).