def curve_branch(depth=3): """Branch Curve angle=22.5, step=40, circle angle=20.5, STEP=2""" _lsystem = lsystem.LSystem('C+C', [('C', 'CC-[-C+C+C]+[-SC-C-sC]')]) _drawing = Drawing(_lsystem, depth, angle=22.5, step=40, circle_angle=20.5, STEP=2) _drawing.draw(0, 0, 1000, 750)
def koch(depth=3): """Simplest L-system example.""" _lsystem = lsystem.LSystem("F", [("F", "F-F++F-F")]) _drawing = Drawing(_lsystem, depth, angle=60, step=100.0 / (depth**2.0), colour1=(200, 50, 50), colour2=(50, 200, 50), circle_angle=20.5, STEP=2, ANGLE=5) _drawing.draw(0, 0, 1000, 750)
def six_pointed_star(depth=3): """A nice 6-pointed angled star""" _lsystem = lsystem.LSystem("F", [("F", "m[F-F++F-F]")]) _drawing = Drawing(_lsystem, 4, angle=60, step=50, colour1=(200, 50, 50), colour2=(50, 200, 50), circle_angle=20.5, STEP=2, ANGLE=5) _drawing.draw(0, 0, 1000, 750)
def doodle(): # _lsystem is basically ignored _lsystem = lsystem.LSystem('f', [('f', 'f')]) _drawing = Drawing(_lsystem, 1, angle=90, step=100, colour1=(200, 50, 50), colour2=(50, 200, 50), circle_angle=20.5, STEP=2, ANGLE=5) # we draw this hand-written string _drawing._draw("FF+F+FF+DF+D", _drawing._rules)
def main(): t = turtle.Turtle() t.speed(0) wd = turtle.Screen() #uncomment the below line of code to make things run faster, but they won't display. #wd.tracer(0,0) print( "Test # 1: The Arrowhead Curve\n######################################\n" ) sys = lsystem.LSystem("arrowheadcurve.txt") sys.createLSystem() sys.drawLSystem(t) t.clear() t.reset() print( "Test # 2: The Hilbert Curve\n######################################\n" ) sys2 = lsystem.LSystem("hilbertcurve.txt") sys2.createLSystem() sys2.drawLSystem(t) t.clear() t.reset() print( "Test # 3: The Dragon Curve\n######################################\n") sys3 = lsystem.LSystem("dragoncurve.txt") sys3.createLSystem() sys3.drawLSystem(t) t.clear() t.reset() print( "Test # 4: The Peano-Gosper Curve\n######################################\n" ) sys4 = lsystem.LSystem("peanogospercurve.txt") sys4.createLSystem() sys4.drawLSystem(t) t.clear() t.reset() print( "Test # 6: The Sierpinski Triangle Curve\n######################################\n" ) sys5 = lsystem.LSystem("sierpinskitrianglecurve.txt") sys5.createLSystem() sys5.drawLSystem(t) print( "Test # 7: Handling File Not Found Error\n######################################\n" ) lsystem.LSystem("not_a_real_file.txt") wd.exitonclick()
def on_draw_button_click(self): #Gather information for drawing symbols = variables_frame.get_symbols() rules = rules_frame.get_rules() settings = settings_frame.get_settings_dict() colors = settings_frame.get_color_palette() #Initialize lsystem object lsystem = lsys.LSystem(settings["axiom"], rules) #Don't exactly know why im iterating the lsystem like this? for _ in range(settings["iteration"]): next(lsystem) #Clear canvas before drawing drawing_frame.draw_canvas.clear_canvas() lsys.draw_lsystem(drawing_frame.draw_canvas, str(lsystem), symbols, (settings["pos_x"], settings["pos_y"]), settings["angle"], settings["turn_angle"], settings["step_length"], settings["line_thickness"], colors, settings["start_color"])
def run_lsystem(): lsystem1 = lsystem.LSystem(fullscreen=True) lsystem1('pentaplexity', 'cross') lsystem1('tiled_square', rotation=[0.0, -0.001]) lsystem1('sierpinski_square') lsystem1.on_close()
import lsystem # KOCH CURVE v1 = lsystem.Variable("F", "F+F-F-F+F", 0, 1) v2 = lsystem.Variable("+", "+", 90, 0) v3 = lsystem.Variable("-", "-", -90, 0) koch = lsystem.LSystem([v1, v2, v3], "F", []) koch.draw("koch.ps", koch.evolve(4), width=0.5) # SIERPINSKI v4 = lsystem.Variable("A", "+B-A-B+", 0, 1) v5 = lsystem.Variable("B", "-A+B+A-", 0, 1) v6 = lsystem.Variable("+", "+", 60, 0) v7 = lsystem.Variable("-", "-", -60, 0) sierpinski = lsystem.LSystem([v4, v5, v6, v7], "A", []) sierpinski.draw("sierpinski.ps", sierpinski.evolve(6), color=[0, 0, 1], width=0.5) # PYTHAGORAS TREE v8 = lsystem.Variable("0", "1[0]0", 0, 1) v9 = lsystem.Variable("1", "11", 0, 2) v10 = lsystem.Variable("[", "[", 45, 0) v11 = lsystem.Variable("]", "]", -45, 0)
def pyramid(depth=3): """Pyramid angle=60""" _lsystem = lsystem.LSystem('FXF--FF--FF', [('F', 'FF'), ('X', '--FXF++FXF++FXF--')]) _drawing = Drawing(_lsystem, depth, angle=60, step=20) _drawing.draw(0, 0, 1000, 750)
def simple_branch(depth=2): """draw a simple branch Branch angle=22.5""" _lsystem = lsystem.LSystem('F', [('F', 'FF-[-F+F+F]+[+F-F-F]')]) _drawing = Drawing(_lsystem, depth, angle=22.5, step=20) _drawing.draw(0, 0, 1000, 750)
def dragon_curve(depth=3): """draw a dragon curve Dragon curve angle=60""" _lsystem = lsystem.LSystem('F', [('F', 'F-F++F-F')]) _drawing = Drawing(_lsystem, depth, angle=60, step=20) _drawing.draw(0, 0, 1000, 750)