コード例 #1
0
ファイル: recursivebsp.py プロジェクト: Derfies/pglib
from pglib.generators.bsp import Bsp
from pglib.generators.image import Image
from pglib.node import Node
from pglib.region import Region
from pglib.samplers.choice import Choice
from pglib.samplers.constant import Constant
from pglib.selectors.base import SelectionMode

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

GRID_SPACING = 16
WIDTH = 40
HEIGHT = 40
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING

# Create tree.
root = Node('root',
            Bsp(Choice([Axis.X, Axis.Y])),
            recurse_while_fn=lambda i, r: r.data.width > 5 and r.data.height >
            5 and i < 1)
root.selector.mode = SelectionMode.DESCENDENTS
root.children.append(Node('next', Image('cross', padding=Constant(1))))

# Add some input data.
root.add_input(Region(0, 0, WIDTH, HEIGHT))

# Create test app and run.
app = AppBase(root, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()
コード例 #2
0
import logging

from pglib.draw.pyglet.appbase import AppBase
from pglib.generators.bspregions import BspRegions
from pglib.node import Node
from pglib.region import Region
from pglib.samplers.range import Range

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

MIN_LEAF_SIZE = 6
MAX_LEAF_SIZE = 20
GRID_SPACING = 10
WIDTH = 64
HEIGHT = 48
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING

# TODO: Port remaining bspregion stuff to bsp
# Create tree.
root = Node('root',
            BspRegions(Range(MIN_LEAF_SIZE, MAX_LEAF_SIZE), padding=Range(5)))

# Add some input data.
root.add_input(Region(0, 0, WIDTH, HEIGHT))

# Create test app and run.
app = AppBase(root, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()
コード例 #3
0
ファイル: grid.py プロジェクト: Derfies/pglib
from pglib.draw.pyglet.appbase import AppBase
from pglib.generators.grid import Grid
from pglib.generators.image import Image
from pglib.node import Node
from pglib.region import Region
from pglib.samplers.constant import Constant
from pglib.samplers.range import Range


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)


GRID_SPACING = 16
WIDTH = 30
HEIGHT = 30
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING


# Create tree.
root = Node('root', Grid(Range(1, 3), Range(1, 3), padding=Constant(1)))
root.add_child(Node('all', Image('pillar_bottom')))

# Add some input data.
root.add_input(Region(0, 0, WIDTH, HEIGHT))

# Create test app and run.
app = AppBase(root, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()
コード例 #4
0
ファイル: city.py プロジェクト: Derfies/pglib
from pglib.region import Region
from pglib.samplers.choice import Choice
from pglib.samplers.constant import Constant
from pglib.samplers.range import Range

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

GRID_SPACING = 10
WIDTH = 100
HEIGHT = 100
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING

# Create tree.
block = Node('block', Grid(Range(2, 4), Range(2, 4)))
footpath = Node('footpath', RegionBase(padding=Constant(1)))
building = Node(
    'footpath',
    Bsp(Choice([Axis.X, Axis.Y])),
    recurse_while_fn=lambda i, r: r.data.width > 5 and r.data.height > 5)

block.add_child(footpath)
footpath.add_child(building)

# Add some input data.
block.add_input(Region(0, 0, WIDTH, HEIGHT))

# Create test app and run.
app = AppBase(block, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()
コード例 #5
0
ファイル: columns.py プロジェクト: Derfies/pglib
from pglib.region import Region
from pglib.samplers.constant import Constant
from pglib.samplers.range import Range
from pglib.selectors.sequence import Sequence

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

GRID_SPACING = 16
WIDTH = 11
HEIGHT = 11
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING

# Create tree.
root = Node('root', Column(Constant(1), padding=Constant(1)))
column = Node('column', RegionBase(padding_y2=Range(7)))
sections = Node('sections', Row(Constant(1)), Sequence())
bot = Node('bot', Image('pillar_bottom'))
mid = Node('mid', Image('pillar_middle'))
top = Node('top', Image('pillar_top'))

root.add_child(column)
column.add_child(sections)
sections.add_child(bot, sections.selector.first)
sections.add_child(mid, sections.selector.middle)
sections.add_child(top, sections.selector.last)

# Add some input data.
root.add_input(Region(0, 0, WIDTH, HEIGHT))
コード例 #6
0
import logging

from pglib.draw.pyglet.appbase import AppBase
from pglib.generators.depthfirstmaze import DepthFirstMaze
from pglib.generators.randomregions import RandomRegions
from pglib.node import Node
from pglib.region import Region
from pglib.samplers.constant import Constant
from pglib.samplers.range import Range

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

GRID_SPACING = 10
WIDTH = 63
HEIGHT = 47
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING

# Create tree.
root = Node('root', RandomRegions(Range(10, 20), Range(10, 20), 200))
root.add_child(Node('maze', DepthFirstMaze(padding=Constant(1))))

# Add some input data.
root.add_input(Region(0, 0, WIDTH, HEIGHT))

# Create test app and run.
app = AppBase(root, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()
コード例 #7
0
ファイル: randomregions.py プロジェクト: Derfies/pglib
import logging

from pglib.draw.pyglet.appbase import AppBase
from pglib.generators.randomregions import RandomRegions
from pglib.node import Node
from pglib.region import Region
from pglib.samplers.range import Range

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

GRID_SPACING = 10
WIDTH = 64
HEIGHT = 48
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING

# Create tree.
root = Node('root', RandomRegions(Range(5, 10), Range(5, 10), 200))

# Add some input data.
root.add_input(Region(0, 0, WIDTH, HEIGHT))

# Create test app and run.
app = AppBase(root, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()
コード例 #8
0
ファイル: recursivemaze.py プロジェクト: Derfies/pglib
import logging

from pglib.draw.pyglet.appbase import AppBase
from pglib.generators.recursivemaze import RecursiveMaze
from pglib.node import Node
from pglib.region import Region

logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

GRID_SPACING = 10
WIDTH = 63
HEIGHT = 47
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING

# Create tree.
# TODO: Can this generator be implemented using the node's recursive function?
root_node = Node('root', RecursiveMaze())

# Add some input data.
root_node.add_input(Region(0, 0, WIDTH, HEIGHT))

# Create test app and run.
app = AppBase(root_node, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()
コード例 #9
0
ファイル: brickwall.py プロジェクト: Derfies/pglib
from pglib.region import Region
from pglib.samplers.constant import Constant


logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)


GRID_SPACING = 10
WIDTH = 30
HEIGHT = 20
WINDOW_WIDTH = WIDTH * GRID_SPACING
WINDOW_HEIGHT = HEIGHT * GRID_SPACING


# Create tree.
root = Node('root', Row(Constant(2), padding=Constant(1)))
node_a = Node('every_second', Column(Constant(6)))
node_b = Node('every_other', Column(Constant(6), padding_x1=Constant(3)))

root.add_child(node_a, lambda data: data[slice(0, len(data), 2)])
root.add_child(node_b, lambda data: data[slice(1, len(data), 2)])
node_a.add_child(Node('bottom', Image('pillar_bottom')))
node_b.add_child(Node('top', Image('pillar_top')))

# Add some input data.
root.add_input(Region(5, 0, WIDTH - 5, HEIGHT))

# Create test app and run.
app = AppBase(root, GRID_SPACING, WINDOW_WIDTH, WINDOW_HEIGHT)
app.run()