def main(): symbols = 'Ff+-' axiom = 'F' N = 4 # rule = generate_random(N) rule = generate_branched(N) print(rule) # return angle = random.choice(range(10, 91, 5)) # angle = 90 iteration = 5 n = 50 animator = LSystemAnimator( interval=1, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, # start_position=(-n//2+10, -10), nlimit=n, ) contd = bool(input("Want to generate?(y/n)").strip().lower() == 'y') if not contd: print("See ya sucker...") sys.exit(0) animator.animate(len(animator.coords)) animator.save("out/curves/random.mp4", fps=30)
def main(): symbols = "Ff+-" axiom = "F" N = 5 # rule = generate_branched(N) rule = generate_continuous(N) print(rule) angle = random.choice(range(0, 181, 1)) iteration = 8 n = 50 animator = LSystemAnimator( interval=1, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, # start_position=(-n//2+10, -10), nlimit=n, line_width=1, ) contd = bool(input("Want to generate?(y/n)").strip().lower() == "y") if not contd: print("See ya sucker...") sys.exit(0) animator.animate(len(animator.coords)) animator.save(f"out/curves/random-{int(time.time())}.mp4", fps=25, dpi=150)
def test2(): # http://www.motionesque.com/beautyoffractals/#! angle = 45 iteration = 4 rule = {'F': 'F- – -F+F+F+F+F+F+F- – -F'} axiom = 'F-F-F-F-F-F-F-F' rule = {'F': 'F+F- -F+F'} axiom = 'F++F++F' # 2 angle = 40 iteration = 2 rule = {'F': 'F---F+F+F+F+F+F+F---F'} axiom = 'F+F+F+F+F+F+F+F+F' # 6 angle = 72 iteration = 3 rule = {'F': 'F-F+F+F+F--F'} axiom = 'F+F+F+F+F' animator = LSystemAnimator(interval=20, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-25, 0)) animator.animate(len(animator.coords)) animator.save("out/test.mp4")
def spiral(): """ Generate spirals using L-System rules """ rule = { 'X': 'XF', 'Y': 'Y+XF+XF' } axiom = '-Y' # change angle to generate non-square spirals # 90 -> Square angle = 90 iteration = 75 n = 40 animator = LSystemAnimator( interval=1, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, # start_position=(-n//2+10, -10), nlimit=n, ) animator.animate(len(animator.coords)) animator.save("out/curves/spiral.mp4", fps=60)
def pentaplexity(): # http://paulbourke.net/fractals/lsys/ angle = 35 iteration = 3 rule = { 'F' : 'F[+FF][-FF]F[-F][+F]F' } axiom = 'F' rule = { 'F' : 'F++F++F|F-F++F' } axiom = 'F++F++F++F++F' angle = 36 iteration = 4 n = 50 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-n//2, -n//2), nlimit=n, ) animator.animate(len(animator.coords)) animator.save("out/curves/pentaplexity.mp4")
def main(): axiom = 'L' rule = { 'L': '-RF+LFL+FR-', 'R': '+LF-RFR-FL+' } angle = 90 animator = LSystemAnimator(interval=50, iteration=5, rule=rule, axiom=axiom, turn_angle=angle) animator.animate(len(animator.coords)) # animator.animate(500) animator.save("out/hilbert.mp4")
def sierpinski_square(): angle = 90 iteration = 5 rule = { 'X': 'XF-F+F-XF+F+XF-F+F-X' } axiom = 'F+XF+F+XF' n = 80 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-n+10, 0), nlimit=n ) animator.animate(len(animator.coords)) animator.save("out/curves/sierpinski-square.mp4")
def sierpinski(): angle = 60 iteration = 7 rule = { 'B' : 'F+B+F', 'F' : 'B−F−B', } axiom = 'F' animator = LSystemAnimator( interval=20, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, # start_position=(-20, 0), nlimit=30 ) animator.animate(len(animator.coords)) animator.save("out/curves/sierpinski.mp4")
def board(): angle = 90 iteration = 4 rule = { 'F': 'FF+F+F+F+FF' } axiom = 'F+F+F+F' n = 60 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-n+15, -n//2), nlimit=n ) animator.animate(len(animator.coords)) animator.save("out/curves/board.mp4")
def snowflake2(): angle = 90 iteration = 4 rule = { 'F': 'F+F-F-F+F' } axiom = 'FF+FF+FF+FF' n = 100 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-n+10, -n+15), nlimit=n ) animator.animate(len(animator.coords)) animator.save("out/curves/snoflake2.mp4")
def sierpinski_arrowhead(): angle = 60 iteration = 5 rule = { 'X': 'YF+XF+Y', 'Y': 'XF-YF-X' } axiom = 'YF+XF+YF-XF-YF-XF-YF+XF+YF' n = 80 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(40, -n+10), nlimit=n ) animator.animate(len(animator.coords)) animator.save("out/curves/sierpinski-arrowhead.mp4")
def dragoncurve(): angle = 90 iteration = 12 rule = { 'X': 'X+YF+', 'Y': '-FX-Y' } axiom = 'FX' n = 60 animator = LSystemAnimator( interval=20, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-20, 20), nlimit=n ) animator.animate(len(animator.coords)) animator.save("out/curves/dragoncurve.mp4")
def tiles(): rule = { 'F': 'FF+F-F+F+FF' } axiom = 'F+F+F+F' angle = 90 iteration = 4 n = 50 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-n//2+10, -10), nlimit=n, ) animator.animate(len(animator.coords)) animator.save("out/curves/tiles.mp4")
def quadratic_koch(): angle = 45 iteration = 3 rule = { 'X': 'X+YF++YF-FX--FXFX-YF+X', 'Y': '-FX+YFYF++YF+FX--FX-YF' } axiom = 'X+X+X+X+X+X+X+X' n = 150 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(-n+40, n//2+15), nlimit=n ) animator.animate(len(animator.coords)) animator.save("out/curves/koch-quadratic.mp4")
def hilbert(): angle = 90 axiom = 'L' rule = { 'L': '-RF+LFL+FR-', 'R': '+LF-RFR-FL+' } iteration = 6 n = 50 animator = LSystemAnimator( interval=5, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, start_position=(n//2, -n//2), nlimit=n ) animator.animate(len(animator.coords)) animator.save("out/curves/hilbert.mp4")
def test3(): # http://paulbourke.net/fractals/lsys/ angle = 35 iteration = 3 rule = {'F': 'F[+FF][-FF]F[-F][+F]F'} axiom = 'F' rule = {'F': 'F++F++F|F-F++F'} axiom = 'F++F++F++F++F' angle = 36 iteration = 4 animator = LSystemAnimator( interval=20, iteration=iteration, rule=rule, axiom=axiom, turn_angle=angle, # start_position=(5, 0) ) animator.animate(len(animator.coords)) animator.save("out/test.mp4")