Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

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


How to Draw Regular Polygons

The Regular Pentagon

This tutorial explains how to draw regular polygons with a computer program. This is a detailed step-by-step guide, featuring many examples. The provided explanations are valid for drawing regular polygons in any programming language.

Start

To start simple, the provided program only draws one red disc and one green arrow.
[Run the program by clicking the 'Run' button]

The first statement of the program sets the center of the red disc to be at coordinates 480 , 360 , which are at the center of the output image. A red disc of radius 20 is then drawn to visualize the center point.

The sleepMs function then makes a small delay, so that the red center point can be easily observed.
[Run the program by clicking the 'Run' button]

The Vector Up

The next statement sets the variable size to equal 200 pixels. Then the vector v is created, of length equal to size.

The vector v is then visualized in the green color by the function DrawArrow . Surprisingly, the vector v has a direction up. In 2D computer graphics, the y coordinate is always reversed upside-down, meaning that the y coordinate increases downwards.
[Run the program by clicking the 'Run' button]

[Click on the 'Next' button (on the page top) to read the next page, or press the F4 key]

Loading...