Triangle Fractal #1

  1. Remember how to draw an equilateral triangle? Write a block that takes a size as input and draws a triangle. (We aren't going to use that block itself on this page, but you're going to write a more complicated riff on triangles, so first you have to know how the simple one works.)

You're going to build a fractal, like the tree fractal in that you specify a size and a level, and higher levels make more complicated pictures:

triangle fractal #1: size (___) , level (___)

At level 1, the result of calling the block should be an equilateral triangle:

equilateral triangle

At level 2, each side of the triangle should be extended with a half-size triangle:

level 2 picture

(Don't click unless you really, really need a super big hint.)

Here are levels 3 and 4:

level 3 picturelevel 4 picture

  1. Okay, finish writing the code. Then try a pretty big level number, 9 or 10, inside a warp block.

    (Don't click unless you need an even bigger hint!)

Your finished product should have produced a shape sort of like this:

four triangles

but with lots of small line segments instead of the grey parts. This should suggest an alternate way to make the shape: Level 1 is a triangle, level 2 is three level-1 versions arrayed around an empty triangle, etc. Write the code for that and compare the two results.