CSC207 - Lab 11
Fractal Recursion

Assigned Oct 21st 2 p.m.
Due Oct 26th 12 p.m.


Overview

Certain elements of mathematics can be naturally described by recursion, as we saw with the factorial function. Today, we will look into the mathematics of fractals and how some of their properties can be described with recursion.

Materials

Description

We will be using the Turtle module in python for our fractals today, like Sierpinski's Triangle, Koch Snowflake, and the Dragon Curve.

To access the Turtle module and define a turtle, we use the following lines of code:

import turtle
t = turtle.Turtle()

With our turtle t, we can make this turtle navigate around the screen, similar to our programming with Scratch.

Some commands for the turtle are:

Step 1

The first type of fractal we will examine uses a simple rewrite rule. Iterative, we can replace a straight line with four new smaller lines, connected up with the following angles.

Now we can repeat, at each level, replace these four new lines in the same manner. Write a recursive function in a file called fractal.pyto have the turtle draw this replacement, with the base case being to draw a line, and the recursive case be to draw these four lines at 1/3 the original distance.

Step 2

Create functions for the following transformations:

Koch 2

Koch 3

C-curve

Dragon Curve

Sierpinski's Triangle

What to Hand In

Log in to cs.centenary.edu through either Secure FTP or WinSCP using your cs login and password. Create a subdirectory from csc207 called lab11. Copy your fractal.py project into this directory. Make sure you have followed the Python Style Guide, and have run your project through the Automated Style Checker.

You must hand in:


© Mark Goadrich 2011, Centenary College of Louisiana