Triangle Fractal in Scratch

Published on

Create a Sierpiński Triangle in Scratch, and learn how Recursion works

In this video, you’ll use Scratch to draw the Sierpiński triangle, a classic fractal made entirely out of smaller repeating triangles. It’s a great way to explore recursion, where something repeats by calling itself with slightly different values each time.

Recursion might sound tricky at first, but this project makes it easy to understand by showing it visually. You’ll see how a simple block of code can repeat itself to create detailed and interesting patterns.

Fractals like the Sierpiński triangle are built using this idea. You start with one shape, then keep repeating a smaller version inside it. Each new triangle fits perfectly into the larger one, and the pattern grows more complex as it continues.

In the tutorial, you’ll:

  • Draw a basic triangle using Scratch’s pen extension
  • Replace fixed values with variables x, y, length so the triangle can move and resize
  • Create a recursive custom block to draw smaller triangles inside the larger one
  • Add an iteration control to decide how many levels deep the recursion goes
  • Explore two different recursive methods:
    1. Placing triangles in specific positions inside the shape
    2. Drawing new triangles along each side as you go
  • Clean up and organize your blocks for a smoother project
  • Make the drawing faster with run without screen refresh, and tweak the look with pen color and size

By the end, you’ll understand how recursion works, how fractals are built, and how to use Scratch in a more advanced and creative way.

Watch the full video to follow along, build your own fractal, and experiment with your own ideas!

The STEAMist Avatar
Happy Coding!
TheSTEAMist