It's Sean!

UK freelance journalist, author
and writer Sean McManus

Printed from www.sean.co.uk. © Sean McManus.
Home > Books > Scratch Programming in Easy Steps > 10 block demos > How to draw any polygon

How to draw a triangle, square, pentagon or any regular shape or polygon in Scratch

Sean McManus, author of Scratch Programming in Easy Steps and Cool Scratch Projects in Easy Steps, shows you how to draw any regular shape or polygon in Scratch

One of the most enjoyable features in the Scratch programming language is the pen, which enables you to draw pictures on the screen by moving sprites around. Here's a simple program I wrote for my Code Club to show them how they can draw a triangle, square, a pentagon, septagon (or heptagon), hexagon, octogon, nonagon, decagon and on and on. I had some fun trying to remember the names for the regular shapes after an eight sided one.

How to draw polygons in Scratch

There are two important numbers you need to know:

My program in the next section calculates this automatically for you, but if you just want to draw a square or another shape, it's clearer to do the maths and drop the numbers in. Here's how to draw a square, for example:

when green flag clicked / clear / pen down / repeat 4 / move 100 steps / turn right 90 degrees / repeat ends

To change the length of the sides, change the number of steps the sprite moves. For shapes with more sides than 16, you'll need to use smaller side lengths, otherwise the sprite will go off the screen.

Program to draw any polygon in Scratch

When green flag clicked / ask how many sides / pen down/ repeat answer / move 50 steps / turn right 360 divided by answer degrees, end repeat

Feel free to share that program card image with your friends on Twitter, Facebook or other social network. Try it with your Code Club group, classroom or family too!

Try the program

Find out more...

Find more 10 block Scratch demos here. For more information on my Scratch books and more bonus content, visit the Scratch Programming in Easy Steps and Cool Scratch Projects in Easy Steps homepages.

Books by Sean McManus

Scratch Programming in Easy Steps

Scratch Programming in Easy Steps

Raspberry Pi For Dummies

Raspberry Pi For Dummies

Learn to program with the Scratch programming language, widely used in schools and colleges.

Set up your Pi, master Linux, learn Scratch and Python, and create your own electronics projects.

Earworm: a novel about the music business

Earworm

Cool Scratch Projects in Easy Steps

Cool Scratch Projects in Easy Steps

An entertaining techno-thriller that takes a slice through the music business: from the boardroom to the stage; from the studio to the record fair.

Discover how to make 3D games, create mazes, build a drum machine, make a game with cartoon animals and more!

More books

Recommended articles

Stylised coloured photo of a synth

Discover my music and home recording articles

Interested in starting home recording? Follow me as I start recording, using instruments such as the Novation MiniNova and Korg Kaossilator, and share my synth and sample-based music online.

Scratch cat and rainbow circle

10-block demos for Scratch programming

Lots of people of all ages are learning to program with Scratch. Discover some useful tricks and techniques in my 10-block Scratch demos, including special effects you can drop into your games.

Paper Raspberry Pi case

Download free book chapters and more!

Download a free case for your Raspberry Pi, and free chapters from my books about the Raspberry Pi, Scratch, web design and more!

©Sean McManus. www.sean.co.uk.