Draw a regular polygon

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that draws any regular polygon with the number of sides entered by the user as the input and the length of each sides equal to 50 steps.

Testing examples:

Test your program with 3, 5 and 10 number of sides as the input.

Languages

Scratch

What it should look like

Click on the green flag to see the expected output of your program.

Recommended blocks
whenclicked
clearpendownpenup
setsidestoanswer
gotox:0y:0move50stepsturn360/sidesdegrees
sayI'll draw a polygon with the number of sides you give me.for3secs
askEnter the number of sides:andwait
repeatsides
Hints
  • A regular polygon has all angles equal and all sides equal.
  • The turning angle or external angle for a regular polygon can be calculated by dividing 360 by the number of sides of the polygon. Note that the turning angle at each vertex of the polygon is different from the inside or the interior angle (i.e. the turning angle and the inside angle of each vertex of the polygon add up to 180 degrees).
  • Block waitsecs waits specified number of seconds, then continues with next block. To be able to see each sides of the polygon being drawn, use the wait block after turning each angle.

Show Scratch solution

Extra Challenge

Extra challenge #1: Write a program that takes the length of a side of a polygon as the input, draws the polygon with the given side and displays its perimeter as the output.