t.right(22.5) def _minus(t, p, a): t.left(22.5) def _leftBracket(t, p, a): p.append(t.pos()) a.append(t.heading()) def _rightBracket(t, p, a): x, y = p.pop() t.penup() t.goto(x, y) t.pendown() t.setheading(a.pop()) definitions = { "F": _F, "[": _leftBracket, "]": _rightBracket, "-": _minus, "+": _plus } l_system = LSystem(seed, rules, definitions, initial_angle=90) l_system.compute(6) l_system.draw()
from l_system import LSystem seed = "FX" rules = { "X": "X+YF+", "Y": "-FX-Y" } def _F(t, p, a): t.forward(8) def _plus(t, p, a): t.right(90) def _minus(t, p, a): t.left(90) definitions = { "F": _F, "-": _minus, "+": _plus } l_system = LSystem(seed, rules, definitions, initial_angle=90) l_system.compute(12) l_system.draw()
t.right(25.7) def _minus(t, p, a): t.left(25.7) def _leftBracket(t, p, a): p.append(t.pos()) a.append(t.heading()) def _rightBracket(t, p, a): x, y = p.pop() t.penup() t.goto(x, y) t.pendown() t.setheading(a.pop()) definitions = { "F": _F, "[": _leftBracket, "]": _rightBracket, "-": _minus, "+": _plus } l_system = LSystem(seed, rules, definitions, initial_angle=90) l_system.compute(7) l_system.draw()
from l_system import LSystem seed = "F+F+F+F" rules = { "F": "FF+F++F+F" } def _F(t, p, a): t.forward(6) def _plus(t, p, a): t.right(90) def _minus(t, p, a): t.left(90) definitions = { "F": _F, "-": _minus, "+": _plus } l_system = LSystem(seed, rules, definitions) l_system.compute(5) l_system.draw()
from l_system import LSystem seed = "F" rules = {"F": "F+F-F-F+F"} def _F(t, p, a): t.forward(8) def _plus(t, p, a): t.left(90) def _minus(t, p, a): t.right(90) definitions = {"F": _F, "+": _plus, "-": _minus} l_system = LSystem(seed, rules, definitions) l_system.compute(4) l_system.draw()