Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Time and Animation [6/9]

This program can move the ball in all directions.

After running and studying the program, add a new variable velocity of type num with an initial value of 300 at the beginning of the source code. Then replace the literal value 300 by the variable velocity in all four places where ball's coordinates x and y get modified.

After that, try some other initial values for the variable velocity.

The variable elapsedTime contains a value of time that has elapsed since the previous animation frame, which is commonly also called the frame time. Examine how the program accomplishes this, what is the purpose of the variable prevTime and how it's value gets computed.

After that, print out the value of the variable elapsedTime immediately after it gets introduced (i.e. after the third statement of the loop).

After running the new program, modify it to also print out the value of the variable prevTime just below the place where where the elapsedTime gets printed out.

After running the program, insert a statement println "Curent time: ", execTm(); just below the place where where the prevTime gets printed out.

Now you can examine how the elapsedTime gets computed. Printout a message "Press the Pause button to examine the output".

After running the program, add a statement sleepMs(500); as the last statement of the loop. Try several other values for the argument of this function and observe how it affects the variable elapsedTime.

Loading...