Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

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

9. Animating Regular Polygons

The given program creates a simple animation of a moving regular polygon.
[Run the program]

The regular polygon is generated by the user-defined function DrawPolygon. This function is called from the last statement in the while loop.

The function DrawPolygon has three parameters. The first parameter is the number of sides. The second parameter is the position. The third parameter is the radius of the polygon in pixels.
[Run the program]

The usual facilities for animating objects in ZedLX have been employed. It is very easy to add animation to ZedLX programs. The source code shows the facilities employed to create this animation: vertical synchronization by vsync, clear screen, and the current time.

On the next page, the polygon can be moved by mouse.

Loading...