Draw a regular polygon

Challenge Level: Growing experience

Learning outcomes

Students will be able to:


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.



What it should look like

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

Recommended blocks
when green flag clicked

pen down

pen up
set [sides v] to (answer)
go to x: (0) y: (0)

move (50) steps

turn cw ((360) / (sides)) degrees
say [I'll draw a polygon with the number of sides you give me.] for (3) secs
ask [Enter the number of sides:] and wait
repeat (sides)
  • 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 wait () secs 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.