Graphics Reference
In-Depth Information
(A): As long as user is not ready to quit
while UserCommand != Quit
(B): Parse the user command
ParseAndExecute(UserCommand)
(C): Periodically update positions and velocities of the balls
if
( OperatingSystem ::SufficientClockTimeHasElapesd)
// update the positions and velocities of all the balls
// in AllWorldBalls
UpdateSimulation()
(D): Draw all balls to the computer screen
// all the balls in AllWorldBalls set
DrawBalls( AllWorldBalls )
(E): Set status bar with number of balls
// Sets status bar: number of balls on screen
EchoToStatusBar()
Listing 1.1. Programming structure from a verbalized solution.
• while the user does not want to quit (A);
• parse and execute the user's command (B);
• update the velocities and positions of the balls (C);
• then draw all the balls (D);
• and finally before we poll the user for another command, tell the user what
is going on by echoing current application state to the status bar (E).
If we translate this verbal solution into a simple programming structure, we get
something like Listing 1.1. In Listing 1.1 we introduce the set of AllWorldBalls
to represent all the balls that are currently active in the application's window. The
only other difference between the pseudocode in Listing 1.1 and our verbalized
solution is in the added elapsed time check in Step (C): SufficientClockTime
HasElapsed . (Recall that the velocities are defined in pixels per second.) To
support proper pixel displacements, we must know real elapsed time between
updates.
Search WWH ::




Custom Search