Triangle Fractal

This shape is called a "Sierpinski (sher-PIN-ski) gasket."


triangle fractal level 6 drawing

    "U6L2-TriangleFractal"Create a new project called U6L2-TriangleFractal
  1. First, write a block that takes a size as input and draws an equilateral triangle.
    triangle size: (40) triangle size: (40) drawing

Growing the Triangle into the Fractal

triangle is the base case. You can modify it, or create a new block with level and size inputs just like tree:
triangle fractal v.1 level: (level #) size: (size #)

If the level is 1, we should see only the triangle:
triangle fractal level 1 drawing

Paul, do you not like my click-for-comment on principle? --bh

Otherwise, a half-size child buds at the end of each side of the parent. At level 2, it should look like this:
triangle fractal level 2 drawing

And at level 3, you should see this:
triangle fractal level 3 drawing

  1. Talk with Your Partner Write the code for triangle fractal.
  2. Using a warp block (to save time) try a big level number, like 8.
  3. The warp block (in the yellow Control palette) makes the scripts inside it run faster by not letting any other scripts run or updating the display until it's finished.
    triangle fractal in warp block in a script

In order to draw the parent triangle, the sprite must turn 120° between sides. For the fractal you just created, that turning happens after drawing the child, but you could turn before the recursive call, or split the turn, with part before and part after the recursive call.

  1. Try some modifications like these:
 
  1. Use for to make an animation that cycles through different turning angle arrangements (that is, 0° and 120°, then 1° and 119°, then 2° and 118°, etc.).
  2. Experiment with the scale factor for the size of the recursive calls. A couple of interesting values are 1/3 and \frac{size}{\sqrt{3}}.