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)

You seem to have teachers help in comments.

can you give more idea what your code is supposed to do?

There is an example in the turtle graphics demo of the Python docs that come with Python.

Here one simple fractal if it could clear up things:

import turtle

def initialize():
    turtle.clearscreen()
    turtle.delay(0)
    turtle.ht()
    turtle.left(90)
    turtle.color('orange')

def check():
    if turtle.color()[0] == 'orange':
        turtle.color('blue')
    else:
        turtle.color('orange')

def drawH(n,s):
    if n:
        check()
        # go to first corner to do H there pen up
        turtle.pu()
        turtle.left(90)
        turtle.forward(s/2)
        turtle.right(90)
        turtle.forward(s/2)
        turtle.left(45)
        turtle.pd()      

        drawH(n-1,s/2)
        turtle.right(45)
        turtle.back(s)
        turtle.right(180+45)
        drawH(n-1,s/2)

        turtle.pu()
        turtle.right(180-45)
        turtle.forward(s/2)
        turtle.right(90)
        turtle.pd()

        turtle.forward(s)

        turtle.pu()       
        turtle.left(90)
        turtle.forward(s/2)
        turtle.right(45)
        turtle.pd()

        drawH(n-1,s/2)
        turtle.right(180-45)
        turtle.forward(s)
        turtle.left(45)
        drawH(n-1,s/2)

        # return home from last corner pen down
        turtle.pu()
        turtle.right(180+45)
        turtle.forward(s/2)
        turtle.left(90)
        turtle.forward(s/2)
        turtle.right(90)
        turtle.pd()

        check()

initialize()
drawH(4, 300)
turtle.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.