In this activity, we will combine what we know about the Pen Extension, variables, and arithmetic operators to draw a shape based on values entered by the user. The user will decide how many sides the shape has and how long each side should be!
Remember: to draw any regular polygon, the turning angle = 360 ÷ number of sides. We can calculate this automatically using the division operator!
Setting Up
- Open PictoBlox and create a New File.
- Select Block Coding as the coding environment.
- Add the Pen Extension from the Extensions menu.
Creating the Variables
- Create a variable called Sides to store the number of sides.
- Create a variable called Length to store the length of each side.
- Create a variable called Angle to store the calculated turning angle.
Building the Script
Now let's build the script. You will find the blocks in the mentioned palettes:
- When flag clicked — Events
- Erase All — Pen
- Go to x: (0) y: (0) — Motion
- Ask (How many sides?) and wait — Sensing
- Set (Sides) to (answer) — Variables
- Ask (How long should each side be?) and wait — Sensing
- Set (Length) to (answer) — Variables
- Set (Angle) to (360 / Sides) — Variables & Operators
- Pen Down — Pen
- Repeat (Sides): Move (Length) steps, Turn (Angle) degrees — Control & Motion
- Pen Up — Pen

Running the Script
- Click the green flag to start the program.
- Enter the number of sides when prompted (e.g. 6 for a hexagon).
- Enter the length of each side (e.g. 100).
- Watch PictoBlox draw your custom shape on the Stage!

Try These Shapes!
Save your file with the name Dynamic Shape before moving on to the next lesson!

.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)
.webp&w=3840&q=75)