def main(): ''' This draws an arrangement of 4 trees, a house, a sky, grass, and a sun. There are two trees to the left of the house and two trees to the right. The two trees to the left, from left to right are the tree defined by the L-system in the systemFL.txt file iterated 5 times and the tree defined by L-system in the the systemDL.txt file iterated 3 times. The two trees to the right of the house from left to right are the tree defined by the L-system in in the systemGL.txt file and iterated 9 times the tree defined by the L-system in the systemDL.txt file iterated 5 times. The house has a square red base, a triangular black roof, a yellow door, and a square window. The sky and grass are rectangles that fill the top and bottom half of the window respectively. The sun was drawn at position (200,190) with a radius of 35. ''' ''' Draws the sky ''' window = ti.TurtleInterpreter(800, 800) window.place(-400, 0, 0) window.drawString('fsFF+F+FF+F+n', 400, 90) ''' Draws the tree defined by the L-system in the system.DL file at (-100,0) where the rules were iterated 3 times at an angle of 22 degrees ''' window.place(-100, 0, 90) window.color('brown') Lsystem1 = ls.Lsystem('systemDL.txt') lstring1 = Lsystem1.buildString(3) window.drawString(lstring1, 10, 22) ''' Draws the tree defined by the L-system in the system.GL file at (100,0) where the rules were iterated 9 times at an angle of 22 degrees ''' window.place(100, 0, 90) Lsystem2 = ls.Lsystem('systemGL.txt') lstring2 = Lsystem2.buildString(9) window.drawString(lstring2, 2, 30) ''' Draws the tree defined by the L-system in the system.FL file at (-200,0) where the rules were iterated 5 times at an angle of 22 degrees ''' window.place(-200, 0, 90) Lsystem3 = ls.Lsystem('systemFL.txt') lstring3 = Lsystem3.buildString(5) window.drawString(lstring3, 2, 22) ''' Draws the tree defined by the L-system in the system.GL file at (200,0) where the rules were iterated 5 times at an angle of 22 degrees ''' window.place(200, 0, 90) Lsystem4 = ls.Lsystem('systemDL.txt') lstring4 = Lsystem4.buildString(5) window.drawString(lstring4, 2, 22) ''' Draws the red base of the house ''' window.place(-15, 0, 0) window.drawString('fRF+F+F+F+n', 44, 90) ''' Draws the black roof of the house ''' window.place(-15, 44, 0) window.drawString('fbF+F+F+n', 44, 120) ''' Draws the yellow door of the house ''' window.place(1.5, 0, 0) window.drawString('fyF+FF+F+FF+n', 10, 90) ''' Draws the black window above the door ''' window.place(1.5, 25, 0) window.drawString('fbF+F+F+F+n', 10, 90) ''' Draws the grass ''' window.place(-400, -400, 0) window.drawString('fgFF+F+FF+F+n', 400, 90) ''' Draws the sun at (200,190) with radius 35 ''' window.sun(200, 190, 35) window.hold()
def main(argv): """ Draw a single tree, using an Lsystem and the TurtleInterpeter This progarm expects the name of an L-system file, the number of iterations to use to generate the tree string, the distance associated with F, and the angle. """ if len(argv) < 2: print( 'usage: %s <lsystem file 1>' ) exit() # trees use systemFL.txt and the change of systemFLr.txt tree = lsystem.Lsystem( argv[1] ) iterations = 5 distance = 8 angle = 30 sx = 600 sy = 600 terp = turtle_interpreter.TurtleInterpreter(sx, sy) x0 = -300 y0 = -250 tstr = tree.buildString( iterations ) terp.setWidth( 2 ) terp.setColor( (0.5, 0.4, 0.3 ) ) terp.place( x0, y0, 90 ) terp.drawString( tstr, distance, angle ) tree = lsystem.Lsystem( argv[1] ) iterations = 4 distance = 8 angle = 30 sx = 600 sy = 600 terp = turtle_interpreter.TurtleInterpreter(sx, sy) x0 = 0 y0 = -250 tstr = tree.buildString( iterations ) terp.setWidth( 2 ) terp.setColor( (0.5, 0.4, 0.3 ) ) terp.place( x0, y0, 90 ) terp.drawString( tstr, distance, angle ) tree = lsystem.Lsystem( argv[1] ) iterations = 3 distance = 8 angle = 30 sx = 600 sy = 600 terp = turtle_interpreter.TurtleInterpreter(sx, sy) x0 = 300 y0 = -250 tstr = tree.buildString( iterations ) terp.setWidth( 2 ) terp.setColor( (0.5, 0.4, 0.3 ) ) terp.place( x0, y0, 90 ) terp.drawString( tstr, distance, angle ) terp.hold()
import turtle_interpreter as ti import lsystem as ls def main() window=ti.TurtleInterpreter(800,800) x=-50 y0=10 for i in range(2,6): x+=25 window.goto(x,y0) for a in (22,25,30): if a==22: y=y0 else: y+=-10 window.goto(x,y) window.place(x,y,90) Lsystem2=ls.Lsystem('treesystem2.txt') lstr2 = Lsystem2.buildString(i) window.drawString(lstr2, 2, a) if __name__=='__main__' main()
def main(): '''Creates 5 lsystems from filenames and then creates an arrangement''' # creates object from lsystem l1 = ls.Lsystem('systemCL.txt') l2 = ls.Lsystem('systemDL.txt') l3 = ls.Lsystem('systemEL.txt') l4 = ls.Lsystem('systemFL.txt') l5 = ls.Lsystem('systemGL.txt') # different iteration number for separate trees num_iter1 = 2 num_iter2 = 3 num_iter3 = 3 num_iter4 = 3 num_iter5 = 5 # creates buildstring functions with specific num_iters s1 = l1.buildString(num_iter1) s2 = l2.buildString(num_iter2) s3 = l3.buildString(num_iter3) s4 = l4.buildString(num_iter4) s5 = l5.buildString(num_iter5) # different angles for each tree and drawstring function angle = 30 angle2 = 20 angle3 = 15 angle4 = 35 angle5 = 25 #creates an object from TI class ti = it.TurtleInterpreter() # sets the colors of the tracer and calls the drawstring function #orients the trees # Tree 1 (systemCL.txt) turtle.pencolor('OliveDrab') '''tree with stem color of olivedrab''' turtle.up() turtle.setposition(-500, -200) turtle.setheading(90) turtle.down() ti.drawString(s1, 25, angle) # Tree 2 (systemDL.txt) turtle.pencolor('Coral') '''tree with stem color of coral''' turtle.up() turtle.setposition(-300, -200) turtle.setheading(90) turtle.down() ti.drawString(s2, 25, angle2) # Tree 3 (systemEL.txt) '''tree with stem color of springgreen''' turtle.pencolor('SpringGreen') turtle.up() turtle.setposition(0, -200) turtle.setheading(90) turtle.down() ti.drawString(s3, 25, angle3) # Tree 4 (systemFL.txt) '''tree with stem color of seagreen''' turtle.pencolor('SeaGreen') turtle.up() turtle.setposition(300, -200) turtle.setheading(90) turtle.down() ti.drawString(s4, 25, angle4) # Tree 5 (systemGL.txt) '''tree with stem color of limegreen''' turtle.pencolor('LimeGreen') turtle.up() turtle.setposition(500, -200) turtle.setheading(90) turtle.down() ti.drawString(s5, 10, angle5) ti.hold()
def __init__(self, distance=5, angle=22.5, color=(0.5, 0.4, 0.3), iterations=3, filename=None): shapes.Shape.__init__(self, distance, angle, color) self.iterations = iterations self.lsys = lsystem.Lsystem(filename)