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) < 3: print('usage: %s <lsystem file 1> <lsystem file 2>') exit() # tree1 use systemFL.txt tree = lsystem.Lsystem(argv[1]) iterations = 5 distance = 8 angle = 25 sx = 600 sy = 600 terp = turtle_interpreter.TurtleInterpreter(sx, sy) x0 = -200 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) # tree2 use systemGL.txt tree = lsystem.Lsystem(argv[2]) iterations = 8 distance = 8 angle = 30 sx = 600 sy = 600 terp = turtle_interpreter.TurtleInterpreter(sx, sy) x0 = 200 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()
def test(): tree1 = Tree(iterations=5, filename='systemJ.txt') tree1.draw(0, 0) tree1.draw(100, 100) tree1.draw(-100, -100) ti.TurtleInterpreter().hold()
def arrangement(): '''creates an arrangement of trees/flowers/plants''' terp = turtle_interpreter.TurtleInterpreter() tree(0, -50, .80, 22.5, 4) t = -325 s = -50 for i in range(2): plant(t, s, .25, 25.7, 4) t = t + 600 a = -350 b = -50 for i in range(9): weed(a, b, .20, 22.5, 5, 180) a = a + 100 x = -300 y = -200 for i in range(5): flower(x, y, .25, 25.7, 4) x = x + 200 y = y m = -350 n = -300 for i in range(8): weed(m, n, .20, 22.5, 5) m = m + 100 terp.hold()
def main(): # create a square object and draw a bunch of them s = shapes.Square() s.setColor((0.3, 0.2, 0.9)) for i in range(36): s.draw(0, -100, scale=0.75, orientation=i * 10) # create a triangle object and draw a bunch of them t = shapes.Triangle() t.setColor((0.8, 0.2, 0.3)) for i in range(20): t.draw(0, 100, scale=0.8, orientation=i * 18) # draw some more squares scale = 0.8 offset = 0 s.setColor((0.1, 0.8, 0.2)) for i in range(20): s.draw(-300, -190 + offset, scale=scale, orientation=90) offset += scale * 100 scale *= 0.8 # draw some more triangles scale = 0.8 offset = 0 t.setColor((0.1, 0.8, 0.2)) for i in range(20): t.draw(300, -190 + offset, scale=scale, orientation=180) offset += scale * 87 scale *= 0.83 # wait turtle_interpreter.TurtleInterpreter().hold()
def main(): """ draw two normal shapes and two jittered versions a test of the jitter drawing method """ # define two strings square = 'F-F-F-F-' triangle = 'F-F-F-' terp = turtle_interpreter.TurtleInterpreter() # draw normal and jittered versions of each shape terp.place(-200, -100) terp.setStyle( 'normal' ) terp.setColor("blue") terp.drawString(square, 100, 90) terp.place(-200, 100) terp.setStyle( 'dotted' ) terp.setColor("red") terp.drawString(square, 100, 90) terp.place(100, -100) terp.setStyle( 'normal' ) terp.setColor("green") terp.drawString(triangle, 100, 120) terp.place(100, 100) terp.setStyle( 'jitter3' ) terp.setColor("purple") terp.drawString(triangle, 100, 120) terp.hold()
def main(): '''Creates lsystem from filename and then creates an arrangement''' # creates object from lsystem l = ls.Lsystem('lsystemextension2.txt') #number of iterations # for growth effect in task 3, made iters a parameter num_iter = 4 # creates buildstring function s = l.buildString(num_iter) #specific angle angle = 30 #creates an object from TI class ti = it.TurtleInterpreter() # sets the colors of the tracer and calls the drawstring function turtle.pencolor('ForestGreen') '''tree with stem color of forestgreen''' turtle.up() turtle.setposition(0, 0) turtle.setheading(90) turtle.down() ti.drawString(s, 50, angle) ti.hold()
def draw(): #use a loop to draw the graph out for i in range(3, 7): main(i, -100 + 100 * (i - 3), 0) turtle.setheading(0) terp = turtle_interpreter.TurtleInterpreter() terp.hold()
def main(x, x0, y0): #x stands for itteration x0 y0 stands for position shape = lsystem.Lsystem('shape.txt') tstr = shape.buildString(x) terp = turtle_interpreter.TurtleInterpreter() terp.goto(x0, y0) terp.drawString(tstr, 30, 360 / x)
def drawSquare(event=None): s = shapes.Square() terp = ti.TurtleInterpreter() (x, y, z) = terp.window2turtle(event.x, event.y) s.draw(x, y, 1)
def tree1(iters, xpos, ypos): '''Creates lsystem from filename and then creates an arrangement''' # creates object from lsystem l1 = ls.Lsystem('lsystemextension1.txt') #number of iterations # for growth effect in task 3, made iters a parameter num_iter1 = iters #creates buildstring function s1 = l1.buildString(num_iter1) #specific angle angle = 15 #creates an object from TI class ti = it.TurtleInterpreter() # sets the colors of the tracer and calls the drawstring function # orients the trees with parameters xpos and ypos # My Tree 1 (mylsystem1.txt) turtle.pencolor('DarkOliveGreen') turtle.pensize(2) '''tree with stem color of olivedrab''' turtle.up() turtle.setposition(xpos, ypos) turtle.setheading(90) turtle.down() ti.drawString(s1, 7, angle)
def main(argv): # create a tree object and draw 3 of them with systemH.txt if len(argv) < 2: print('usage: %s <lsystem file 1>' % (argv[0]) ) exit() tr = tree.Tree(distance=5, angle=22.5, color="olive", iterations=5, filename=argv[1]) tr.draw(-100, -200, 1, 90) tr.draw(0, -200, 1, 90) tr.draw(100, -200, 1, 90) # create a fillTriangle object and draw a bunch of them fT=shapes.fillTriangle() fT.setColor( (0.8, 0.2, 0.3) ) for i in range(20): fT.draw(250, -100, scale=0.75, orientation=i*30) # create a 5sides object and draw it fS=shapes.fiveSide() fS.setColor( "red" ) fS.draw(-300, -50, scale=0.75, orientation=0) # create a star object and draw a red one S=shapes.Side() S.setColor( "red" ) S.draw(-300, 200, scale=0.75, orientation=0) # create a star object and draw a yellow one SY=shapes.SideYellow() SY.setColor( "yellow" ) SY.draw(200, 200, scale=0.75, orientation=0) turtle_interpreter.TurtleInterpreter().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) < 5: print 'usage: %s <lsystem file 1> <iterations> <distance> <angle>' % ( argv[0]) exit() tree = lsystem.Lsystem(argv[1]) iterations = int(argv[2]) distance = float(argv[3]) angle = float(argv[4]) sx = 600 sy = 600 terp = turtle_interpreter.TurtleInterpreter(sx, sy) x0 = 0 y0 = -250 tstr = tree.buildString(iterations) terp.width(2) terp.color((0.5, 0.4, 0.3)) terp.place(x0, y0, 90) terp.drawString(tstr, distance, angle) terp.hold()
def main(): """ test function for the new jitter style creates a 3x3 array with jitter increasing right to left """ # create a Square and a Triangle object s = shapes.Square() s.setStyle('jitter') t = shapes.Triangle() t.setStyle('jitter') g = 0.2 # Put them together in a 3x3 grid for i in range(3): r = 0.2 + 0.3 * i for j in [0, 1, 2]: b = 0.8 - 0.3 * i t.setColor((b, g, r)) t.setJitter(j * 3) t.draw(-180 + 150 * j, 180 - 150 * i, scale=0.4, orientation=0) s.setColor((r, g, b)) s.setJitter(j * 3) s.draw(-200 + 150 * j, 200 - 150 * i, scale=0.8, orientation=0) turtle_interpreter.TurtleInterpreter().hold()
def main(): ''' This attaches the draw monument function to the command control right click on a laptop or the right mouse click. ''' terp=ti.TurtleInterpreter() terp.setRightMouseCallback(drawmon)
def main(): terp = it.TurtleInterpreter() pyr = '[F+F+F+[F(135)+(45)^F(90)&F](45)+(45)^F(90)&F]' terp.setStyle('normal') terp.color((0.4, 0.5, 0.6)) terp.place(0, 0, zpos=0) terp.roll(-90) terp.drawString(pyr, 50, 90) terp.width(2) terp.setStyle('jitter') terp.color((0.6, 0.1, 0.7)) terp.place(150, 0, zpos=-200) terp.drawString(pyr, 70, 90) terp.width(1) terp.setJitter(5) terp.color((0.2, 0.5, 0.3)) terp.place(-230, 0, zpos=50) terp.drawString(pyr, 80, 90) terp.hold()
def tree2(iters, xpos, ypos): '''Creates lsystem from filename and then creates an arrangement''' # creates object from lsystem l2 = ls.Lsystem('lsystemextension2.txt') #number of iterations # for growth effect in task 3, made iters a parameter num_iter2 = iters # creates buildstring function s2 = l2.buildString(num_iter2) #specific angle angle2 = 30 #creates an object from TI class ti = it.TurtleInterpreter() # sets the colors of the tracer and calls the drawstring function # orients the trees with parameters xpos and ypos # My Tree 2 (mylsystem2.txt) turtle.pencolor('SandyBrown') '''tree with stem color of coral''' turtle.up() turtle.setposition(xpos, ypos) turtle.setheading(90) turtle.down() ti.drawString(s2, 50, angle2)
def main(): ''' makes a scene with a triangle, square, pentagon, hexagon, and septagon with rainbow colors ''' scale = 0.8 # create a triangle object and draw a bunch of them t = Triangle() t.setColor("red") t.draw(-380, -100, scale=scale, orientation=90) # create a square object and draw a bunch of them s = Square() s.setColor("orange") s.draw(-260, -100, scale=scale, orientation=90) p = Pentagon() p.setColor("yellow") p.draw(-140, -100, scale=scale, orientation=90) h = Hexagon() h.setColor("green") h.draw(20, -100, scale=scale, orientation=90) sept = Septagon() sept.setColor("blue") sept.draw(190, -100, scale=scale, orientation=90) # wait ti.TurtleInterpreter().hold()
def draw(self, xpos, ypos, scale=1.0, orientation=0): terp = it.TurtleInterpreter() terp.place(xpos, ypos, orientation) terp.color(self.color) terp.setJitter(self.jitterSigma) terp.setStyle(self.style) terp.setDotSize(self.dotSize) terp.width(self.linewidth) terp.drawString(self.string, self.distance * scale, self.angle)
def draw(self, xpos, ypos, scale=1.0, orientation=0): # create a TurtleInterpreter object TI = turtle_interpreter.TurtleInterpreter() # use the TurtleInterpreter object to place the turtle at (xpos, ypos, orientation) TI.place(xpos, ypos, orientation) # use the TurtleInterpreter object to set the turtle color to self.color TI.setColor(self.color) # use the TurtleInterpreter object draw the string TI.drawString(self.istring, (self.distance) * scale, self.angle)
def draw(self, xpos, ypos, scale=1.0, orientation=0,roll=0,pitch=0,zpos=0): '''Draws the shape at (xpos,ypos,zpos) at scale scale and orientation orientation''' interp=ti.TurtleInterpreter() interp.place(xpos,ypos,orientation,roll,pitch,zpos) interp.setStyle(self.style) interp.setJitter(self.jitterSigma) interp.width(self.width) interp.color(self.color) interp.drawString(self.string,scale*self.distance,self.angle)
def shapeFromString(): '''places simple Lsystem shapes''' terp = turtle_interpreter.TurtleInterpreter() pentagonFlower(-100, 100, 1.5, 60, 1) cross(100, 100, 1.5, 90, 1) square(-50, 0, 2, 90, 1) hexagon(50, 0, 2, 60, 2) triangle(0, 0, 3, 120, 1) terp.hold()
def draw(self, xpos, ypos, scale=1.0, orientation=0): # create a TurtleInterpreter object shp = ti.TurtleInterpreter() # use the TurtleInterpreter object to place the turtle at (xpos, ypos, orientation) shp.place(xpos, ypos, orientation) # use the TurtleInterpreter object to set the turtle color to self.color shp.setColor(self.color) # use the TurtleInterpreter object draw the string shp.drawString(self.string, self.distance * scale, self.angle)
def main(argv): """ main function draws the items into the image needs an lsystem tree file to make the trees """ if len(argv) < 2: print('Usage: python %s <lsystem file>' % (argv[0])) exit() # background s = shapes.Square() s.setString('{F-F-F-F-}') s.setColor((0.88, 0.92, 1.0)) s.draw(-400, 650, 8) # clouds in the sky c = TwoBlobs() c.setStyle('jitter') c.setJitter(10) for i in range(6): c.draw(random.randint(-450, 400), random.randint(200, 400), random.random() + 0.6) # mountains in the background m = BrokenTriangle() m.setStyle('jitter') m.setJitter(10) for i in [0, 3, 1, 2]: m.setColor((random.random() * 0.05 + 0.6, random.random() * 0.05 + 0.65, random.random() * 0.1 + 0.7)) m.draw(-450 + i * 150 + random.randint(-10, 10), -200 + random.randint(0, 100), random.random() * 0.3 + 2) # grass g = Grass() g.setStyle('jitter') g.setJitter(3) for i in range(2000): g.draw(-450 + random.randint(0, 900), random.randint(-450, -200), 4) # Trees t = tree.Tree(iterations=3, filename=argv[1]) t.setStyle('jitter') for i in range(90): x = -450 + i * 10 + random.randint(-5, 5) y = -300 + random.randint(0, 100) scale = (y / -300.0 + random.random() * 0.1) * 0.1 o = 90 + random.randint(-5, 5) t.draw(x, y, scale, o) # lake c.setColor((0.1, 0.2, 0.8)) c.draw(-300, -300, 5, 0) # hold turtle_interpreter.TurtleInterpreter().hold()
def main(): # assign the lsystem string to a new parameter sun = lsystem.Lsystem('sun.txt') tree1 = lsystem.Lsystem('systemCL.txt') tree2 = lsystem.Lsystem('systemDL.txt') tree3 = lsystem.Lsystem('tree2.txt') tree4 = lsystem.Lsystem('systemFL.txt') tree5 = lsystem.Lsystem('systemGL.txt') #then apply iteration to the string tstr1 = sun.buildString(5) tstr2 = tree1.buildString(3) tstr3 = tree2.buildString(3) tstr4 = tree3.buildString(3) tstr5 = tree4.buildString(3) tstr6 = tree5.buildString(5) turtle.tracer(False) sky() grassland() turtle.setheading(90) house(250, -180, 200) terp = turtle_interpreter.TurtleInterpreter() # draw the shapes out terp.color('red') terp.goto(-250, 250) terp.drawString(tstr1, 30, 30) turtle.setheading(90) terp.color((0.5, 0.4, 0.3)) terp.goto(-50, -300) terp.drawString(tstr2, 10, 30) turtle.setheading(90) terp.color((0, 0, 0)) terp.goto(150, -250) terp.drawString(tstr3, 10, 30) turtle.setheading(90) terp.color((0, 0, 0)) terp.goto(-280, -320) terp.drawString(tstr4, 10, 30) turtle.setheading(90) terp.color((0.7, 0.2, 0.3)) terp.goto(-200, -250) terp.drawString(tstr5, 10, 30) turtle.setheading(90) terp.color((0.5, 0.5, 0.5)) terp.goto(300, -300) terp.drawString(tstr6, 5, 30) terp.hold() turtle.update()
def drawmon(event=None): ''' This draws a monument when you hit control and hit the right key pad or the right mouse click ,depending on the computer used, at the specific position you perform either command on. Works best before you rotate the scene. ''' terp=ti.TurtleInterpreter() m=shapes.monument() (x,y,z) = terp.window2turtle(event.x, event.y) m.draw(x,y,1)
def draw(self, xpos, ypos, scale=1.0, orientation=0): '''draws the object at a given position, size, and orientation''' object = t.TurtleInterpreter() object.place(xpos, ypos, orientation) object.color(self.color) object.setStyle(self.style) object.setJitter(self.jitterSigma) object.setDotSize(self.dotSize) object.width(self.linewidth) object.drawString(self.istring, self.distance * scale, self.angle)
def wreathGrowth(): '''shows wreath growing by increasing the iterations''' terp = turtle_interpreter.TurtleInterpreter() x = -300 y = 0 iterations = 3 for i in range(3): springWreath(x, y, .5, 25.7, iterations) x = x + 250 iterations = iterations + 2 terp.hold()
def blockGrowth(): '''shows block Lsystem growing by increasing the iterations''' terp = turtle_interpreter.TurtleInterpreter() x = -300 y = 0 iterations = 2 for i in range(3): block(x, y, .40, 90, iterations) x = x + 300 iterations = iterations + 1 terp.hold()
def pinkFlowerGrowth(): '''shows pinkFLower growing by increasing the iterations''' terp = turtle_interpreter.TurtleInterpreter() x = -300 y = 0 iterations = 2 for i in range(3): pinkFlower(x, y, .80, 36, iterations) x = x + 250 iterations = iterations + 1 terp.hold()
def main(): '''calls the different trees''' Tree1 = Tree(distance=5, color=(0.1, 0.5, 0.3), filename='systemDL.txt') Tree1.draw(100, -200) Tree2 = Tree(distance=10, color=(0.1, 0.5, 0.3), filename='systemFL.txt') Tree2.draw(0, -200) Tree3 = Tree(distance=15, color=(0.1, 0.5, 0.3), filename='systemDL.txt') Tree3.draw(-100, -200) terp = t.TurtleInterpreter() terp.hold()