Hey,
So I need help with fractal project, Pythagoras Tree, and below is the code i need to complete. And I really have no idea how to finish.
from PIL import Image
from movieSolution import *
import math
class ETree(GO):
#---------------------- Begin given functions ----------------------------
def __init__(self, color, initSize, order, bottomLeft):
""" Just an initializer (or class constructor) """
GO.__init__(self)
self.color = color
self.initSize = initSize
self.generate(order, bottomLeft)
def addBoxLeft(self, bottomLeft, length, angle):
""" This function will add a square box to the
TFFTree. Each side of the square will be length long. The bottom left
corner of the square will be located at bottomLeft, which is a tuple, and
the entire square will be rotated counter-clockwise around bottomLeft by
angle degrees. """
topLeft = (bottomLeft[0], bottomLeft[1] - length)
bottomRight = (bottomLeft[0] + length, bottomLeft[1])
boxGO = GO()
boxGE = rectangle(topLeft, bottomRight, self.color, True)
boxGO.addGE(boxGE)
boxGO.rotate(-angle, bottomLeft)
self.GEList.append(boxGE)
def addBoxRight(self, bottomRight, length, angle):
""" This function will add a square box to the TFFTree. Each side of the
square will be length long. The bottom right corner of the square will be
located at bottomRight, which is a tuple, and the entire square will be
rotated clockwise around bottomRight by angle degrees. """
topLeft = (bottomRight[0]-length, bottomRight[1]-length)
boxGO = GO()
boxGE = rectangle(topLeft, bottomRight, self.color, True)
boxGO.addGE(boxGE)
boxGO.rotate(angle, bottomRight)
self.GEList.append(boxGE)
#----------------------- End given functions -----------------------------
def generate(self, order, bottomLeft):
""" This function should create the first square and then call
self.generateLeft to recursively generate the left side of the tree and
self.generateRight to recursively generate the right side of the tree.
The first square should have a length of self.initSize and a color of
self.color. It's bottom left corner should be placed at bottomLeft. """
# student's code goes here
print('This function not yet implemented.')
# create the first box
# do the left box
# do the right box
def generateLeft(self, order, length, bottomLeft, angle):
""" This function should create a box using the given length, bottomLeft,
and angle parameters. It should then recursively generate its left and
right sides. If order is equal to 0 or length < 1, this function should
just return. """
# your code goes here
print('This function not yet implemented.')
# the base case
# add the box
# do the left box
# do the right box
def generateRight(self, order, length, bottomRight, angle):
""" This function should create a box using the given length,
bottomRight, and angle parameters. It should then recursively generate
its left and right sides. If order is equal to 0 or length < 1, this function
should just return. """
# your code goes here
print('This function not yet implemented.')
# the base case
# add the box
# do the right box
# do the left box
# running this will test if everything is working or not
if __name__ == '__main__':
treeMovie = movie()
f = frame()
for i in range(1, 13):
# create a fractal of order i
t = ETree((0,0,0), 100, i, (400, 475))
# add the fractal to the movie as a new frame
f.addGO(t)
treeMovie.addImage(f.drawFrameColorSize((255,255,255), (900,500)))
im = f.drawFrameColorSize((255,255,255), (900, 500))
treeMovie.addImage(im)
treeMovie.addImage(im)
treeMovie.addImage(im)
treeMovie.play(10)