################################################################################ # File: lab5.py # # Name: Harry Q. Bovik # # Andrew ID: hqbovik # # Class: 15-110 Summer 2 2011 # # Date: July 24, 2011 # ################################################################################ from Tkinter import * import random # Hard-coded global state constants # Feel free to play around with these # Window size constant. Use this for creating the window. windowSize = 800 # Triangle *height* constant. Used by initTriangle triSize = 800 # The recursion limit. maxDepth = 6000 # Initial 2D coordinate for the chaos game method. # Use this to start off your chaos function. anchor = (0, 0) # Command to tell Python to increase the recursion limit. sys.setrecursionlimit(maxDepth + 100) # Computes an initial equilateral triangle that is centered in the window. # Note that ax, ay, bx, by, cx, and cy are global variables that can be # accessed by other functions after initTriangle() is called def initTriangle(windowSize, triSize): global ax, ay global bx, by global cx, cy (ax, ay) = (windowSize / 2, (windowSize - triSize) / 2) (bx, by) = (ay, (windowSize + triSize) / 2) (cx, cy) = (by, by) return # Function that provides a random vertex. def randomVertex(): global ax, ay global bx, by global cx, cy # Chooses a random int from 0 to 2 and returns the corresponding vertex vertexList = [(ax, ay), (bx, by), (cx, cy)] i = random.randint(0, 2) return vertexList[i] ################################################################################ # STUDENT CODE GOES HERE # ################################################################################ # Calculate the midpoint of two 2D points def midpoint(pointA, pointB): return pointA # Function that draws one triangle def drawTriangle(triangle): return # Recursive function that generates the Sierpinski triangle def sierpinski(depth, triangle): return # Function that draws one pixel def drawPixel(point): return # Recursive function that generates n points def chaos(n, start): return # Wrapper function that makes initial recursive call to sierpinski() def sierpinskiWrapper(): return # Wrapper function that makes initial recrusive call to chaos() def chaosWrapper(): # The main function that sets up the Tk window and canvas widgets def run(): global widgetDict # Initialize the original triangle initTriangle(windowSize, triSize) return