top of page

Sierpiński Triangle

Lesson Overview

In this lesson, students will learn how to use Scratch to draw a fractal (Sierpiński Triangle). Before solving this problem, they will first learn how to define subroutines for drawing different polygons by setting single or multiple parameters to My blocks. After mastering drawing polygons using blocks related to angles (e.g., turn XX degree) and side length (e.g., move XX), in the task of drawing fractals students will break down the steps of drawing the Sierpiński Triangle by discovering patterns within different levels and thus develop the concept of recursion by defining my blocks.

Prior Knowledge

  • Mathematics: properties of regular polygons (e.g., side length and angle)

  • Scratch: Know how to use blocks such as ‘ask’, ‘move’, ‘turn’, ‘repeat’, ‘if… then…else…’ and define ‘My block’.

Lesson Objectives

  1. To understand the meaning and difference between parameter and variable.

  2. To know how to draw different polygons with the same and different side lengths in Scratch with geometry knowledge.

  3. To gain the concept of recursion and use the recursion function to draw Sierpiński Triangles.

Mathematics & CT Outcomes

  1. Mathematics: the concept of fractal geometry; drawing method of regular polygons and Sierpiński Triangles. 

  2. CT Skills: loops (repeat XX); conditionals (if…then…else…), subroutines (create my blocks; parameters; recursion); sequence; decomposition (break down the Sierpiński Triangles into small parts); automation (draw Sierpiński Triangles automatically)

Teaching Resources 

The Desmos Activity used in this Task.

Lesson Details

Introduction Problem: Drawing Polygons

1. Drawing Squares: using a function with the parameter “Length”.


2. Drawing Polygons: using a function with two parameters “Length” and “Number of sides”.


Sample Work


Main Problem: Sierpiński Triangle

Today, we will learn how to use Scratch to draw Fractal Geometry. One of the fractals is Sierpiński Triangles.

Try to draw the Level 4 Sierpiński Triangle on paper. How does a computer draw Sierpiński triangles?

What’s novel with the computer’s way of drawing the Sierpiński Triangle?

We can also use recursion to draw Sierpiński Triangles. What is Recursion?

Recursion is a process in which a function calls itself as a subroutine. It occurs when a thing is defined in terms of itself. This allows the function to be repeated several times, since it calls itself during its execution.

Now, it’s your turn! Based on the guidelines, try to create a Sierpiński Triangle!


Step 1: Define and believe your function.

Step 2: Find the recursion relationship of the function.

Step 3: Set the level 1 detail.

You may use the codes shown on the right:

Go to then Click Remix and ADD TO STUDIO!

Student's Work

About these samples: 

There are two myblocks defined in this work, a “setup” myblock which sets the starting point and direction of the drawing and another myblock “Sierpiński Triangle” is set to draw the fractal. In the “Sierpiński Triangle” myblock, the [if...then...else...] block is used to determine the level of the Sierpiński Triangle. Also embedded in this conditional block are two repeat blocks and a call of “Sierpiński Triangle” myblock as a subroutine. The first repeat block is used to draw the smallest triangle, while the second repeat block forms a recursion with the outer block to draw the triangle at the target level which make a Sierpiński Triangle.

Possible Challenges and Misconceptions

In this work, the problem was in the My block.

As the figure drawn is a fractal, the figure is formed by repeating itself over and over again, and in My block the student does not call the My block that draws the triangle again at Level >1, but simply uses an [if...then...else...] block that could not get the computer to draw the Sierpiński Triangle.

Students’ Reflection

Q1: To solve this problem, what kinds of programming techniques, codes, and mathematics do you expect to use?

  • Parameters, loops movements.

  • My block, function, pen up, variables, addition

  • Very obviously, variables, draw, move steps, turn n degrees

  • Create block, degree, variable, divide

  • The technique of solving doubles or sequences.

  • Loop, for I in range forever.

  • Parameters and variabls.

  • I think I need superior maths.


The author would like to thank all the anonymous teachers and students who participated in this research.

bottom of page