Introduction to Programming

Activity 2: Draw a Triangle

Lesson 3: Drawing Shapes

Great job drawing a square! Now let's take it a step further and draw a triangle. A triangle has 3 sides and 3 corners — and just like the square, we can draw it using the Pen Extension and a simple loop.

A triangle has 3 equal sides and 3 corners. At each corner, the sprite turns 120°. Since 3 × 120° = 360°, the sprite completes a full turn and the shape closes perfectly.

Setting Up

  • Open PictoBlox and create a New File.
  • Select Block Coding as the coding environment.
  • Make sure the Pen Extension is added. If not, click the Extensions button at the bottom left of the Code tab to add it.

Building the Script

Follow the steps below to build the script that draws a triangle. You will find the blocks in the mentioned palettes:

  • When flag clicked — Events
  • Erase All — Pen
  • Go to x: (0) y: (0) — Motion
  • Pen Down — Pen
  • Repeat (3) — Control
  • Move (100) steps — Motion
  • Turn (120) degrees — Motion
  • Pen Up — Pen
Block coding script showing when flag clicked, erase all, go to x 0 y 0, pen down, repeat 3 loop containing move 100 steps and turn 120 degrees, then pen up
Complete script to draw a triangle in PictoBlox

Running the Script

  • Click the green flag to run the script.
  • Watch the sprite draw a triangle on the Stage!
  • Click the green flag again at any time to redraw — the Erase All block will clear the previous drawing first.
A triangle drawn on the PictoBlox stage using the pen extension
The triangle drawn on the Stage after running the script

Comparing Square vs Triangle

Square vs Triangle

PropertySquareTriangle
Number of Sides43
Turning Angle90°120°
Repeat Count43
Total Turn360°360°
Notice that no matter the shape, the total turning angle always adds up to 360°. This is the secret to drawing any regular polygon!

Customizing Your Triangle

  • Change the pen color using the 'Set Pen Color to ()' block to make a colorful triangle.
  • Change the pen size using the 'Set Pen Size to ()' block to make the lines thicker or thinner.
  • Try changing the step count to make a bigger or smaller triangle.
Save your file with the name Draw a Triangle before moving on!

Subscribe to our newsletter.

Get updates to news and events.