Learn to Program with ZedLX

Free Online Programming Course for Beginners

Simple Motion [6/10]

This program draws a moving disc.
[Run the program]

The value of variable i specifies the distance from the left edge of the screen to the center of the blue disc.

In each iteration of the for loop, one animation frame is drawn to the screen.

Exercises:

  1. Can you make the disc move faster, WITHOUT changing the sleepMs(30) statement?

    Hint 1

    What is the step size of the for loop?

    Solution 1

    for #i=1..860 +=5

    Solution 2

    disc(i*5, 300, 100, /blue);

  2. Change the sleep time in the sleepMs procedure call to value 400, in order to view each animation frame separately.

Loading...