What will you learn?
Creating a Pentagon
We are going to write a program that draws a pentagon. Let's begin by understanding what a pentagon is.
How do we program our pentagon?
What is the size of the angle? If all of the angles add up to 360 degrees, we divide 360 by 5 to get 72 degrees.
- The pentagon has 5 sides.
- All of the 5 angles are equal.
- The total of the angles is 360 degrees.
What is the size of the angle? If all of the angles add up to 360 degrees, we divide 360 by 5 to get 72 degrees.
If we were writing instructions to draw a rectangle, we might write:
- Draw a line 100 units long.
- Create a 72 degree angle.
- Repeat steps 1 and 2 five times.
Here is the program. Click on it to interact with it.
How does our program work? Let's look at the instructions that draw the pentagon.