示例#1
0
    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()
示例#2
0
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()
示例#3
0
文件: tree.py 项目: TerrayTM/l-system
    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()
示例#4
0
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()
示例#5
0
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()