Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

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

7. Drawing a Random Regular Polygon

The first statement of the source code sets the colors to dark blue and gold. The clearScr function allows a default background color and a default drawing color to be provided. It enables both colors to be specified in a single line of the source code. In the source code of this program, other statements do not specify explicit colors anymore, which causes the default drawing colors to be used.
[Run the program]

The Random Number of Sides

The function rn with an argument of 10 returns a random number in range of 1 - 10. The constant 2 is added to that random value, so that the number of sides n will equal a random number in range 3-12.
[Run the program]

The body of the for loop has been modified so that the random regular polygon is filled with color.
[Run the program]

On the next page, the regular star septagon is generated.

Loading...