def main(argv): # check if there are enough arguments if len(argv) < 3: print('usage: %s <lsystem filename> <lsystem filename>' % (argv[0])) exit() # create the lsystem from a file lsys = ls.createLsystemFromFile(argv[1]) # build the lsystem string with 3 iterations lstr = ls.buildString(lsys, 3) dist = float(10) angle = float(90) # draw the abstract1 turtle.tracer(False) nonabstract(lstr, -100, -100, dist, angle) # create the lsystem from a file lsys = ls.createLsystemFromFile(argv[2]) # build the lsystem string with 3 iterations lstr = ls.buildString(lsys, 4) dist = float(3) angle = float(25) # draw the abstract2 turtle.tracer(False) nonabstract(lstr, 100, -200, dist, angle) # wait it.hold()
def main(): ''' Imports mountain scene from project 3 and adds three equally sized trees, one with red leaves, one with orange leaves, and another one with yellow leaves. The size of the leaves from largest to smallest are red, orange, and yellow. From left to right the trees have red, orange, and yellow leaves. The trees are spaced 200 pixels from each other in the x direction. The branches are brown. ''' bsl.myOtherScene(0, 0, 0.8) ''' Draws mountain scene from Project 3 at 0.8 times its original size ''' my_lsys1 = ls.init() ls.setBase(my_lsys1, 'F') ls.addRule(my_lsys1, ['F', 'F FF-[-F+F+FRB]+[+F-F-FRB]']) ''' Creates L system that draws tree with red leaves and brown branches ''' my_lsys2 = ls.init() ls.setBase(my_lsys2, 'F') ls.addRule(my_lsys2, ['F', 'F FF-[-F+F+FOB]+[+F-F-FOB]']) ''' Creates L system that draws tree with orange leaves and brown branches ''' my_lsys3 = ls.init() ls.setBase(my_lsys3, 'F') ls.addRule(my_lsys3, ['F', 'F FF-[-F+F+FYB]+[+F-F-FYB]']) ''' Creates L system that draws tree with yellow leaves and brown branches. ''' lstr1 = ls.buildString(my_lsys1, 2) lstr2 = ls.buildString(my_lsys2, 2) lstr3 = ls.buildString(my_lsys3, 2) turtle.setheading(90) x = -400 for i in (lstr1, lstr2, lstr3): x += 200 turtle.up() turtle.goto(x, -80) turtle.down() turtle.color("brown") ti.drawString(i, 5, 20) ''' Draws each tree with red, orange, and yellow leaves in that order with the trees spaced 200 pixels apart in the x direction starting at (-400,-80). For each tree, the L-system that makes up each tree is iterated 2 times. ''' ti.hold() #holds the screen open until the user clicks or types 'q'
def main(argv): ''' Draws something in the turtle window using the L system that is in a file that is entered on the command line. The second and third input is respectively what distance the turtle should go forward and the angle the turtle should turn. ''' if len(argv) < 4: print 'usage: %s <lsystem filename> <distance> <angle>' % (argv[0]) exit() lsys = ls.createLsystemFromFile( argv[1] ) lstr = ls.buildString( lsys, 3 ) dist = float( argv[2] ) angle = float( argv[3] ) turtle.tracer(False) turtle.left(90) drawString( lstr, dist, angle ) hold()
def main(argv): '''creates a set of 9 trees based on a lsystem in a 3x3 grid.''' # check if there are enough arguments if len(argv) < 1: print "Usage : python grid.py <in_filename>" exit() lsys_filename = argv[1] # create the lsystems from a file lsys = ls.createLsystemFromFile( lsys_filename ) x = [-200, 0, 200] y = [100, -150, -350] iters = [1, 2, 3] angles = [22, 46, 60] dist = 10 for c in range( len(iters)): for r in range( len(iters)): turtle.up() turtle.speed(300) turtle.goto(x[c], y[r]) turtle.setheading(0) turtle.left(90) s = ls.buildString( lsys, iters[c] ) turtle.down() it.drawString( s, dist, angles[r] ) # wait and update turtle.update() it.hold()
def grid(key, x, y, scale): # create the lsystem from a file lsys = ls.createLsystemFromFile(key) # build the lsystem string with i iterations for i in range(3): lstr = ls.buildString(lsys, i + 1) for j in [22, 46, 60]: angle = float(j) oldheading = turtle.heading() turtle.up() turtle.goto(x, y) turtle.down() turtle.right(270) turtle.color(0.5, 0.6, 0.8) turtle.width(2) it.drawString(lstr, scale * 0.75, angle) turtle.setheading(oldheading) y = y - scale * 30 y = y + scale * 90 x = x + scale * 30 return
def main(): ''' Draws a 3 by 3 grid of trees. From left to right, the number of iterations of the L-system goes from 1 to 3 and from top to bottom, the angle of the L-system is 22, 40, and 60. ''' my_lsys = ls.init() ls.setBase(my_lsys, 'F') ls.addRule(my_lsys, ['F', 'F FF-[-F+F+F]+[+F-F-F]']) ''' Creates an L system that can draw a tree. ''' x = -400 y0 = 100 for i in range(1, 4): x += 200 turtle.up() turtle.goto(x, y0) turtle.down() for a in (22, 40, 60): if a == 22: y = y0 else: y += -150 turtle.up() turtle.goto(x, y) turtle.down() turtle.setheading(90) lstr = ls.buildString(my_lsys, i) ti.drawString(lstr, 5, a) ti.hold()
def tree1(argv, x, y): lsys_filename1 = argv[1] lsys1 = ls.createLsystemFromFile( lsys_filename1 ) print lsys1 num_iter1 = int( 3 ) dist = float( 5 ) angle1 = float( 22 ) s1 = ls.buildString( lsys1, num_iter1 ) #draw lsystem1 '''this is my first lsystem with filename mysystem1.txt with 3 iterations and with angle = 45 dist = 10''' turtle.tracer(False) turtle.speed(50000000) turtle.up() turtle.goto(0,0) turtle.goto(x, y) turtle.down() turtle.pencolor('White') it.drawString( s1, dist, angle1 ) # wait and update turtle.update()
def sun(argv): lsys_filename3 = argv[3] lsys3 = ls.createLsystemFromFile( lsys_filename3 ) print lsys3 num_iter3 = int( 3 ) dist = 5 angle3 = float( 120 ) s3 = ls.buildString( lsys3, num_iter3 ) #draw lsystem3 '''this is my third lsystem with filename mysystem3.txt with 3 iterations and with angle = 45 dist = 10''' turtle.up() turtle.goto(0,0) turtle.goto(300, 200) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('Red') it.drawString( s3, dist, angle3 ) # wait and update turtle.update()
def tree2(argv, x, y): lsys_filename2 = argv[2] lsys2 = ls.createLsystemFromFile( lsys_filename2 ) print lsys2 num_iter2 = int( 3 ) dist = float( 5 ) angle2 = float( 30 ) s2 = ls.buildString( lsys2, num_iter2 ) #draw lsystem2 '''this is my second lsystem with filename mysystem2.txt with 5 iterations and with angle = 120 dist = 10''' turtle.up() turtle.goto(0,0) turtle.goto(x,y) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('White') it.drawString( s2, dist, angle2 ) # wait and update turtle.update()
def sun(argv): lsys_filename3 = argv[3] lsys3 = ls.createLsystemFromFile(lsys_filename3) print lsys3 num_iter3 = int(3) dist = 5 angle3 = float(120) s3 = ls.buildString(lsys3, num_iter3) #draw lsystem3 '''this is my third lsystem with filename mysystem3.txt with 3 iterations and with angle = 45 dist = 10''' turtle.up() turtle.goto(0, 0) turtle.goto(300, 200) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('Red') it.drawString(s3, dist, angle3) # wait and update turtle.update()
def tree1(argv, x, y): lsys_filename1 = argv[1] lsys1 = ls.createLsystemFromFile(lsys_filename1) print lsys1 num_iter1 = int(3) dist = float(5) angle1 = float(22) s1 = ls.buildString(lsys1, num_iter1) #draw lsystem1 '''this is my first lsystem with filename mysystem1.txt with 3 iterations and with angle = 45 dist = 10''' turtle.tracer(False) turtle.speed(50000000) turtle.up() turtle.goto(0, 0) turtle.goto(x, y) turtle.down() turtle.pencolor('Brown') it.drawString(s1, dist, angle1) # wait and update turtle.update()
def tree2(argv, x, y): lsys_filename2 = argv[2] lsys2 = ls.createLsystemFromFile(lsys_filename2) print lsys2 num_iter2 = int(3) dist = float(5) angle2 = float(30) s2 = ls.buildString(lsys2, num_iter2) #draw lsystem2 '''this is my second lsystem with filename mysystem2.txt with 5 iterations and with angle = 120 dist = 10''' turtle.up() turtle.goto(0, 0) turtle.goto(x, y) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('White') it.drawString(s2, dist, angle2) # wait and update turtle.update()
def main(argv): # check if there are enough arguments if len(argv) < 2: print('usage: %s <lsystem filename>' % (argv[0])) exit() # create the lsystem from a file lsys = ls.createLsystemFromFile(argv[1]) # build the lsystem string with 3 iterations lstr = ls.buildString(lsys, 3) dist = float(5) angle = float(25) # draw the abstract1 turtle.tracer(False) abstract(lstr, -200, 100, dist, angle, "red", 0) abstract(lstr, -200, 100, dist, angle, "yellow", 90) abstract(lstr, -200, 100, dist, angle, "blue", 180) abstract(lstr, -200, 100, dist, angle, "green", 270) # wait it.hold()
def main(argv): # check if there are enough arguments if len(argv) < 4: print('usage: %s <lsystem filename> <distance> <angle>' % (argv[0])) exit() # create the lsystem from a file lsys = ls.createLsystemFromFile(argv[1]) # build the lsystem string with 3 iterations lstr = ls.buildString(lsys, 3) dist = float(argv[2]) angle = float(argv[3]) # draw the two pairs turtle.tracer(False) pair(lstr, -100, 100, dist, angle) pair(lstr, 100, -100, dist * 0.5, angle) # wait it.hold()
def main(argv): # check if there are enough arguments if len(argv) < 4: print 'usage: %s <lsystem filename> <distance> <angle>' % (argv[0]) exit() # create the lsystem from a file lsys = ls.createLsystemFromFile(argv[1]) # build the lsystem string with 3 iterations lstr = ls.buildString(lsys, 3) dist = float(argv[2]) angle = float(argv[3]) # draw the lsystem turtle.tracer(False) turtle.left(90) it.drawString(lstr, dist, angle) # wait turtle.update() it.hold()
def main(argv): # check if there are enough arguments if len(argv) < 4: print 'usage: %s <lsystem filename> <distance> <angle>' % (argv[0]) exit() # create the lsystem from a file lsys = ls.createLsystemFromFile( argv[1] ) # build the lsystem string with 3 iterations lstr = ls.buildString( lsys, 3 ) dist = float( argv[2] ) angle = float( argv[3] ) # draw the lsystem turtle.tracer(False) turtle.left(90) it.drawString( lstr, dist, angle ) # wait turtle.update() it.hold()
def main(): ''' Uses L systems to create scene with light blue sky, green grass, a sun in the top right corner, and a tree with brown branches. ''' my_lsys1 = ls.init() ls.setBase(my_lsys1, 'F') ls.addRule(my_lsys1, ['F', 'FF+F+FF+F+']) lstr1 = ls.buildString(my_lsys1, 1) ''' Creates L-system that represents a rectangle that is twice as wide as it is high. Thus, this L-system can draw both a rectangluar light blue sky and green grass since this L-system is iterated once. ''' turtle.up() turtle.goto(-315, -285) turtle.begin_fill() turtle.down() turtle.color('green') ti.drawString(lstr1, 310, 90) turtle.end_fill() ''' Draws rectangular green grass starting at (-315,285) ''' turtle.up() turtle.goto(-315, 25) turtle.begin_fill() turtle.down() turtle.color('lightblue') ti.drawString(lstr1, 310, 90) turtle.end_fill() ''' Draws rectangular light blue sky starting at (-315,25) ''' turtle.up() turtle.goto(250, 180) turtle.begin_fill() turtle.down() turtle.color('yellow') turtle.circle(50) turtle.end_fill() ''' Draws sun at (250,180) ''' my_lsys2 = ls.init() ls.setBase(my_lsys2, 'F') ls.addRule(my_lsys2, ['F', 'F[+F]F[-F][F]']) ''' Creates new L-system that draws a tree with multiple branches at (0,-225) ''' lstr2 = ls.buildString(my_lsys2, 5) turtle.setheading(90) turtle.up() turtle.goto(0, -225) turtle.down() turtle.color("brown") ti.drawString(lstr2, 5, 20) ''' Draws the tree with multiple brown branches starting at (0,-225) and the L-system that makes up the tree is iterated 5 times. ''' ti.hold() #holds the screen open until the user clicks or types 'q'
def main(argv): # check if there are enough arguments if len(argv) < 10: print "Usage : python abstract.py 3*<in_filename> 3*<num_iterations>" exit() # assign lsys_filenames to command line filename arguments lsys_filename1 = argv[1] lsys_filename2 = argv[2] lsys_filename3 = argv[3] # create the lsystems from a file lsys1 = ls.createLsystemFromFile(lsys_filename1) lsys2 = ls.createLsystemFromFile(lsys_filename2) lsys3 = ls.createLsystemFromFile(lsys_filename3) print lsys1 print lsys2 print lsys3 # assign num_interations to command line number arguments num_iter1 = int(argv[4]) num_iter2 = int(argv[5]) num_iter3 = int(argv[6]) # build the lsystem string with given number of iterations s1 = ls.buildString(lsys1, num_iter1) s2 = ls.buildString(lsys2, num_iter2) s3 = ls.buildString(lsys3, num_iter3) print s1 print s2 print s3 # assign distances and angles to given command line inputs dist = float(argv[7]) angle1 = float(argv[8]) angle2 = float(argv[9]) angle3 = float(argv[10]) # draw the lsystems #draw lsystem1 '''this is my first lsystem with filename mysystem1.txt with 3 iterations and with angle = 45 dist = 10''' turtle.tracer(False) turtle.up() turtle.goto(-400, 0) turtle.down() turtle.left(90) turtle.pencolor('Green') it.drawString(s1, dist, angle1) #draw lsystem2 '''this is my second lsystem with filename mysystem2.txt with 5 iterations and with angle = 120 dist = 10''' turtle.up() turtle.goto(0, 0) turtle.goto(0, 0) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('Red') it.drawString(s2, dist, angle2) #draw lsystem3 '''this is my third lsystem with filename mysystem3.txt with 3 iterations and with angle = 45 dist = 10''' turtle.up() turtle.goto(0, 0) turtle.goto(300, -100) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('Blue') it.drawString(s3, dist, angle3) # wait and update turtle.update() it.hold()
def main(argv): # check if there are enough arguments if len(argv) < 10: print "Usage : python abstract.py 3*<in_filename> 3*<num_iterations>" exit() # assign lsys_filenames to command line filename arguments lsys_filename1 = argv[1] lsys_filename2 = argv[2] lsys_filename3 = argv[3] # create the lsystems from a file lsys1 = ls.createLsystemFromFile( lsys_filename1 ) lsys2 = ls.createLsystemFromFile( lsys_filename2 ) lsys3 = ls.createLsystemFromFile( lsys_filename3 ) print lsys1 print lsys2 print lsys3 # assign num_interations to command line number arguments num_iter1 = int( argv[4] ) num_iter2 = int( argv[5] ) num_iter3 = int( argv[6] ) # build the lsystem string with given number of iterations s1 = ls.buildString( lsys1, num_iter1 ) s2 = ls.buildString( lsys2, num_iter2 ) s3 = ls.buildString( lsys3, num_iter3 ) print s1 print s2 print s3 # assign distances and angles to given command line inputs dist = float( argv[7] ) angle1 = float( argv[8] ) angle2 = float( argv[9] ) angle3 = float( argv[10] ) # draw the lsystems #draw lsystem1 '''this is my first lsystem with filename mysystem1.txt with 3 iterations and with angle = 45 dist = 10''' turtle.tracer(False) turtle.up() turtle.goto(-400, 0) turtle.down() turtle.left(90) turtle.pencolor('Green') it.drawString( s1, dist, angle1 ) #draw lsystem2 '''this is my second lsystem with filename mysystem2.txt with 5 iterations and with angle = 120 dist = 10''' turtle.up() turtle.goto(0,0) turtle.goto(0,0) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('Red') it.drawString( s2, dist, angle2 ) #draw lsystem3 '''this is my third lsystem with filename mysystem3.txt with 3 iterations and with angle = 45 dist = 10''' turtle.up() turtle.goto(0,0) turtle.goto(300,-100) turtle.down() turtle.setheading(0) turtle.left(90) turtle.pencolor('Blue') it.drawString( s3, dist, angle3 ) # wait and update turtle.update() it.hold()