CS2 Computational Thinking for Scientists - Lab 05

CS2 Computational Thinking for Scientists - Lab 05

In this lab, we will experiment with recursive Python programs for drawing fractals. I have created a Python module fractals.py. Download this module into a folder in your desktop. Run the following commands in order to import the functions in fractals.py in to your IDLE platform:
import os
os.chdir("/Users/koc/Desktop/abc")
from fractals import *
Change the file path from above to the one you will be using.
Also, import the turtle and the math modules:
import turtle, math
since we will be using them as well.

The following recursive functions are available in fractals.py module:

  • koch1(turtle,order,length): Koch fractal whose top corner points up.
  • koch2(turtle,order,length): Koch fractal whose top corner points down.
  • kochtr1(turtle,order,length): Koch triangle made up from koch1 fractals.
  • kochtr2(turtle,order,length): Koch triangle made up from koch2 fractals.
  • kochsq1(turtle,order,length): Koch square made up from koch1 fractals.
  • kochsq2(turtle,order,length): Koch square made up from koch2 fractals.

  • torn1(turtle,order,length): Torn fractal whose top corner points up.
  • torn2(turtle,order,length): Torn fractal whose top corner points down.
  • tornsq1(turtle,order,length): Torn square made up from torn1 fractals.
  • tornsq2(turtle,order,length): Torn square made up from torn2 fractals.

To use any one of these functions, first create a turtle, and place it in the window into an appropriate corner, and then call the function. For example:
tony = turtle.Turtle() # create a turtle
tony.up()              # pen up
tony.goto(-100,-100)   # left bottom corner
tony.down()            # pen down
koch1(tony,4,200)      # order = 4 and length = 200

Report: This lab requires a report. Experiment with these functions, and create several different triangles, squares, or other polygons whose sides are Koch or Torn or other types of fractals. Finally, submit your "best looking fractal", by emailing your Python program and an image (screen shot) file of the fractal.


The lab report (if required) is due 5pm, Friday Feb 13.