Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

How to Draw N-sided Regular Polygons [10/11]

10. Following the Mouse Motion

The polygon is now following the mouse pointer.
[Run the program]

To create this interactive demo, the usual facilities for animating objects in ZedLX have been employed. The value of elapsedTime has been computed in the usual maner, as it is descibed in the ZedLX tutorial chapter "Time and Animation".

The vector difference is the difference between the current mouse position and the center of the polygon. To make the polygon move slowly, the position of the polygon is changed in small steps. The position is held in the variable named position. The position is moved in each frame by only a small fraction of the difference.

On the next page, the polygon can be moved by the keyboard keys.

Loading...