コード例 #1
0
def tree():
    global angle
    global thickness
    global length

    angle = 15
    thickness = 8
    length = 10

    t.pendown()
    t.penblock(WOOD)
    rules = {
        'A': [(0.55, '^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'),
              (0.25, '^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]
    }

    axiom = 'fA'
    material = WOOD

    t.penwidth(thickness)
    t.penblock(material)

    stack = []

    def push():
        global length
        global thickness
        stack.append((length, thickness))
        t.push()
        thickness = thickness * 0.6
        if length == 10:
            length = 9
        elif length == 9:
            length = 8.4
        else:
            length = length * 0.75
        if thickness < 1:
            thickness = 1
        if length <= 1.6:
            t.penblock(LEAVES_OAK_PERMANENT)
        t.penwidth(thickness)

    def pop():
        global length
        global thickness
        length, thickness = stack.pop()
        t.pop()

    dictionary = {
        '[': push,
        ']': pop,
        '^': lambda: t.pitch(angle),
        '>': lambda: t.roll(angle),
        'f': lambda: t.go(length)
    }

    lsystem.lsystem(axiom, rules, dictionary, 11)
コード例 #2
0
def tree():
    global angle
    global thickness
    global length

    angle = 15
    thickness = 8
    length = 10

    t.pendown()
    t.penblock(WOOD)
    rules = {'A': [(0.55,'^f[^^f>>>>>>A]>>>[^^f>>>>>>A]>>>>>[^^f>>>>>>A]'),
                    (0.25,'^f>>[^^f>>>>>>A]>>>[^^f>>>>>>A]')]}

    axiom = 'fA'
    material = WOOD

    t.penwidth(thickness)
    t.penblock(material)

    stack = []
    def push():
        global length
        global thickness
        stack.append((length,thickness))
        t.push()
        thickness = thickness * 0.6
        if length == 10:
            length = 9
        elif length == 9:
            length = 8.4
        else:
            length = length * 0.75
        if thickness < 1:
            thickness = 1
        if length <= 1.6:
            t.penblock(LEAVES_OAK_PERMANENT)
        t.penwidth(thickness)

    def pop():
        global length
        global thickness
        length,thickness = stack.pop()
        t.pop()

    dictionary = {
        '[': push,
        ']': pop,
        '^': lambda: t.pitch(angle),
        '>': lambda: t.roll(angle),
        'f': lambda: t.go(length)

    }

    lsystem.lsystem(axiom, rules, dictionary, 11)
コード例 #3
0
#

import lsystem
from mcturtle import *
t = Turtle()
t.pendelay(0)
t.turtle(None)
t.penblock(BRICK_BLOCK)
t.gridalign()

# http://mathforum.org/advanced/robertd/lsys2d.html
rules = {'X': 'XF-F+F-XF+F+XF-F+F-X'}


def go():
    t.startface()
    for i in range(4):
        t.go(4)
        t.pitch(90)
    t.endface()
    t.go(4)


dictionary = {
    'F': go,
    '+': lambda: t.yaw(90),
    '-': lambda: t.yaw(-90),
}

lsystem.lsystem('X', rules, dictionary, 4)
コード例 #4
0

def go():
    # draw a wall segment with a door
    t.pendown()
    t.penblock(BRICK_BLOCK)
    t.startface()
    for i in range(4):
        t.go(4)
        t.pitch(90)
    t.endface()
    t.penup()
    t.go(2)
    t.pendown()
    t.penblock(AIR)
    t.pitch(90)
    t.go(1)
    t.penup()
    t.pitch(180)
    t.go(1)
    t.pitch(90)
    t.go(2)


dictionary = {
    '+': lambda: t.yaw(90),
    '-': lambda: t.yaw(-90),
    'F': lambda: go()
}
lsystem.lsystem('FX', rules, dictionary, 14)
コード例 #5
0
# rules from
# http://kanga.nu/~claw/blog/2008/11/16/game-design-tools/inkscape-l-systems-svg-penrose-and-other-tilings/
rules = {
    'W': '+++X--F--ZFX+',
    'X': '---W++F++YFW-',
    'Y': '+ZFX--F--Z+++',
    'Z': '-YFW++F++Y---',
}
axiom = 'W'

colorIndex = 0


def go():
    global colorIndex
    t.penblock(COLORS[colorIndex % len(COLORS)])
    colorIndex += 1
    t.go(6)


dictionary = {
    'F': go,
    '+': lambda: t.yaw(-30),
    '-': lambda: t.yaw(30),
    '[': lambda: t.push(),
    ']': lambda: t.pop()
}

lsystem.lsystem(axiom, rules, dictionary, 6)
コード例 #6
0
t.pendelay(0)
t.turtle(None)
t.gridalign()

# Hilbert curve axiom and production rule by Stan Wagon, Mathematica in Action (chapter 6), W. H. Freeman and Co., 1991
rules = {'X': '^<XF^<XFX+F^>>XFX&F->>XFX+F>X+>'}

count = 0


def go():
    global count
    # seven segments per basic unit
    if count % 7 == 0:
        t.penblock(Block(block.WOOL.id, (count / 7) % 16))
    count += 1
    t.go(4)


dictionary = {
    'F': go,
    '+': lambda: t.yaw(90),
    '-': lambda: t.yaw(-90),
    '^': lambda: t.pitch(90),
    '&': lambda: t.pitch(-90),
    '>': lambda: t.roll(90),
    '<': lambda: t.roll(-90)
}

lsystem.lsystem('X', rules, dictionary, 3 if len(argv) < 2 else int(argv[1]))
コード例 #7
0
# ensure angles are always integral multiples of 90 degrees
t.gridalign()

rules = {'X':'X+YF+', 'Y':'-FX-Y'}

def go():
# draw a wall segment with a door
    t.pendown()
    t.penblock(BRICK_BLOCK)
    t.startface()
    for i in range(4):
        t.go(4)
        t.pitch(90)
    t.endface()
    t.penup()
    t.go(2)
    t.pendown()
    t.penblock(AIR)
    t.pitch(90)
    t.go(1)
    t.penup()
    t.pitch(180)
    t.go(1)
    t.pitch(90)
    t.go(2)

dictionary = { '+': lambda: t.yaw(90),
               '-': lambda: t.yaw(-90),
               'F': lambda: go() }
lsystem.lsystem('FX', rules, dictionary, 14)
コード例 #8
0
t.penblock(STAINED_GLASS_PURPLE)
t.gridalign()

# rules from
# http://kanga.nu/~claw/blog/2008/11/16/game-design-tools/inkscape-l-systems-svg-penrose-and-other-tilings/
rules = { 'W': '+++X--F--ZFX+',
          'X': '---W++F++YFW-',
          'Y': '+ZFX--F--Z+++',
          'Z': '-YFW++F++Y---',
          }
axiom = 'W'

colorIndex = 0
def go():
    global colorIndex
    t.penblock(COLORS[colorIndex % len(COLORS)])
    colorIndex += 1
    t.go(6)

    

dictionary = {
  'F': go,
  '+': lambda: t.yaw(-30),
  '-': lambda: t.yaw(30),
  '[': lambda: t.push(),
  ']': lambda: t.pop()
  }

lsystem.lsystem(axiom, rules, dictionary, 6)
コード例 #9
0
ファイル: hilbert.py プロジェクト: arpruss/raspberryjam-pe
t = Turtle()
t.pendelay(0)
t.turtle(None)
t.gridalign()

# Hilbert curve axiom and production rule by Stan Wagon, Mathematica in Action (chapter 6), W. H. Freeman and Co., 1991
rules = { 'X': '^<XF^<XFX+F^>>XFX&F->>XFX+F>X+>' }

count = 0

def go():
  global count
  # seven segments per basic unit
  if count % 7 == 0:
      t.penblock(Block(block.WOOL.id, (count/7)%16))
  count += 1
  t.go(4)

dictionary = {
  'F': go,
  '+': lambda: t.yaw(90),
  '-': lambda: t.yaw(-90),
  '^': lambda: t.pitch(90),
  '&': lambda: t.pitch(-90),
  '>': lambda: t.roll(90),
  '<': lambda: t.roll(-90)
  }

lsystem.lsystem('X', rules, dictionary, 3 if len(argv)<2 else int(argv[1]))
コード例 #10
0
#
# Code under the MIT license by Alexander Pruss
#

import lsystem
from mcturtle import *
t = Turtle()
t.pendelay(0)
t.turtle(None)
t.penblock(BRICK_BLOCK)
t.gridalign()

# http://mathforum.org/advanced/robertd/lsys2d.html
rules = { 'X': 'XF-F+F-XF+F+XF-F+F-X' }

def go():
    t.startface()
    for i in range(4):
        t.go(4)
        t.pitch(90)
    t.endface()
    t.go(4)

dictionary = {
  'F': go,
  '+': lambda: t.yaw(90),
  '-': lambda: t.yaw(-90),
  }

lsystem.lsystem('X', rules, dictionary, 4)