CS 4 Computer Science Bootcamp

CS 4 Computer Science Bootcamp
Winter 2019

Lab 4

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:

  • kochLeft(turtle,order,length): Koch fractal whose top corner points up.
  • kochRight(turtle,order,length): Koch fractal whose top corner points down.
  • kochtrLeft(turtle,order,length): Koch triangle made up from Koch fractals.
  • kochtrRight(turtle,order,length): Koch triangle made up from Koch fractals.
  • kochsqLeft(turtle,order,length): Koch square made up from Koch fractals.
  • kochsqRight(turtle,order,length): Koch square made up from Koch fractals.

  • tornLeft(turtle,order,length): Torn fractal whose top corner points up.
  • tornRight(turtle,order,length): Torn fractal whose top corner points down.
  • tornsqLeft(turtle,order,length): Torn square made up from Torn fractals.
  • tornsqRight(turtle,order,length): Torn square made up from Torn 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
kochLeft(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 the Python program and image (screenshot) of your "best looking fractal".


This lab report is due 5pm Friday Aug 30