Triangle Fractal

In this lab, you will create several recursive, fractal-drawing procedures.

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

triangle fractal animation levels 1 to 8

  1. Open your project "U3L1-FractalArt"; save it as "U7L2-TriangleFractal".
  2. Run nested triangle, size: (175). Then look inside the block and remind yourself and your partner how it works.
  3. Predict how the shape will change if you change the 9 in (size)>(9) to 2 and run the instruction again. Then try it and see if it does what you expect.
    The warp block (in the yellow Control palette) makes the script inside it run faster by not letting any other scripts run or updating the display until it's finished.
    warp{nested triangle, size:(175)}
  4. Then set the value from 2 back to 9.

The expression (size)>(9) sets the base case of the recursion in the nested triangle block. But using the size input to control the depth of the recursion isn't very satisfactory. For example, when you tried nested triangle, size: (175) you may have thought, "That's an interesting picture, but it's too big to fit on the stage. Let me try size 100 instead." If you actually tried it, were you disappointed in the result?

  1. If you didn't try it then, try it now.

You already know a better way to control the recursion: have another input, level, to control the depth of the recursion separately from the overall size of the picture. That's what you did in the tree fractal.

  1. Make a block triangle fractal, level: ( ) size: (). You can use the code of your existing nested triangle block as a starting point.
  2. Try several triangle fractal drawings, all with size 100, but with values of level from 1 up to 10. Make sure they do what you expected.
  3. Generalize your procedure by adding an input:
    polygon fractal, level: ( ) number of sides: ( ) size: ().