CSC 100: The Beauty and Joy of Computing

A printable PDF is available.

Homework 3 – Fractal Designs – Due Wednesday, Nov. 6

In Activity 3 of Lab 9, you experimented with a recursively generated self-similar shape called a Sierpinski Triangle. In mathematics there are many such shapes that are known as "fractals," and the Wikipedia page on Fractals has a good discussion with different examples (you aren't required to read this, but you might find it interesting). While fractals are often studied simply for the beauty of the drawings, there are practical uses too: at the bottom of the Wikipedia page is an example that shows a fractal construction of an artificial mountain - many game designers use fractals for generating realistic artificial landscapes for games, and due to the self-similarity of the structure the game can zoom in on this artificial structure at whatever scale is needed. In this homework, you will learn about some self-similar shapes that go beyond the Sierpinski Triangle that you saw in Lab 6, see some examples of where they occur both in nature and in design, and then experiment in BYOB with drawing some recursively-generated shapes.

Self-similar shapes and drawings can have a high level of symmetry and infinitely-detailed structure. Many societies and artists have found great beauty in fractal designs, and in particular many African geometric designs that are found in fabrics and in village design are based on fractals. This homework has a couple of initial activities that you should do before getting to the main part of the assignment. I have put dates on these activities to indicate when I will assume you have done them, so we can discuss these items briefly in class. However, you are encouraged to work faster than this so you have plenty of time to think about and work on the BYOB code.

Activity 1 (finish no later than Wednesday, October 23): Watch the video of the TED talk "Ron Eglash: The fractals at the heart of African designs" at http://www.ted.com/talks/ron_eglash_on_african_fractals.html. The video is 17 minutes, and you should spend at least 30 minutes thinking about the ideas and exploring fractals online.

Activity 2 (finish no later than Monday, October 28): Go through the online lesson on fractals and design at http://csdt.rpi.edu/african/African_Fractals/index.html, which should take about one hour to complete (that depends on how much time you spend playing with the applets).

Activity 3 (finish no later than Wednesday, November 6): You should create BYOB scripts to draw at least two of the fractals from the preceding online lesson, where the two should be chosen from the list at the end of this activity. How much time should this take? It could take anywhere from as little as one hour to as much as twenty very frustrating hours. If you get really stuck, seek help!

What's great about fractal drawings is that it takes very little code to draw very intricate shapes. The bad part is that for such a small amount of code, it can be very difficult to wrap your mind around. In Lab 9 you created code to draw a Sierpinski Triangle. Let's walk through how to make a BYOB script to draw a Koch curve (the first example in the lesson above). This will give you another example to look at, think about, and possibly play around with on the computer before you have to make your own fractal drawing code.

The idea is fairly straightforward: we pass two parameters, for the size of the drawing and the number of levels of recursion to use. The base case is a 0 level Koch curve, and will just draw a single straight line of the specified length for the base case. At higher levels we make four segments, each of which is a Koch curve at a smaller level. Here's the code:

That's the entire recursive script, and all that's needed to draw Koch curves at whatever level of detail you want. There are a few things you really need to understand about this code which are not obvious at first glance – make sure you understand why each of these is important before you try writing your own fractal drawing code!

  • All direction adjustments are relative adjustments and not absolute – in other words, in recursive code, always use "turn" blocks and never the "point in direction" block.

  • The "sub length" that is calculated depends on the fact that we're turning 60 degrees. If you had a different "seed shape" or even just a different angle in this shape, you'd need to solve a little trigonometry problem to get this right.

  • The sequence of turns should always leave the drawing sprite with the same direction that it started in – in other words, all turns should cancel out: in this case we have two counterclockwise turns of 60 degrees, which is exactly balanced by a clockwise turn of 120 degrees.

You also need a driver script, and below is an example of a driver script that draws a level 0 Koch curve (remember, this is just a straight line) - it has to set the starting position and orientation, make sure the screen is cleared and the pen is down, and then uses the block we just defined to make the drawing. The output is shown to the right.

A level 0 Koch curve is very boring, of course. Here's what it looks like if we change the level parameter to 1, 2, 3, 4, and 5:

Isn't that cool? Just a little bit of BYOB code can draw these amazingly intricate, symmetric, and infinitely detailed pictures!

Now for your assignment: You are to create BYOB scripts to draw two of the fractal designs described in the web lesson you followed for the previous activity, restricted to the ones listed below. I think it would be great if you chose one shape from the "fractals in nature" examples and one from the "African fractals" examples, but really any two will be OK. Here are the shapes you can choose from:

Fractals in nature:

  • Organic branching structures ("Application 3")

  • Queen Anne's Lace ("Applications 3")

  • Fern ("Applications 3")

  • Da Vinci branching ("Applications 4")

  • Dendrite ("Applications 5")

  • River basin ("Applications 5")

  • Sierpinski carpet ("Applications 6")

  • Lungs ("Applications 7")

  • Neuron ("Applications 7" - warning, this one is pretty hard)

African fractals:

  • Logone-Bini ("Culture 2" - this one is tricky)

  • Golden rectangle ("Culture 2")

  • Baila village ("Culture 4")

  • Nankani ("Culture 6")

  • Fulani wedding blanket ("Culture 9")

  • Ethiopian cross ("Culture 11")

  • Ghanian bull horn ("Culture 12")

  • Kitwe community clinic ("Culture 17")