Example #1
0
def main():
    arguments = docopt(__doc__)
    filename = arguments['<filename>']
    empty = arguments['--empty'] is not None
    rand = arguments['--rand'] is not None
    dimensions = None
    if empty:
        dimensions = arguments['--empty']
    if rand:
        dimensions = arguments['--rand']
    if dimensions is not None:
        dimensions = [int(x) for x in dimensions.split('x')]
        if rand:
            cells = engine.randomized_cells(dimensions)
        else:
            cells = Cells(dimensions=dimensions)
        with open(filename, 'w') as f:
            f.write(str_from_cells(cells))
        return
    
    with open(filename, 'r') as f:
        cells = cells_from_str(f.read())
    engine.tick(cells)
    with open(filename, 'w') as f:
        f.write(str_from_cells(cells))
Example #2
0
def main():
    scale = 4

    x, y = 100, 100
    cells = engine.randomized_cells((x,y))
    white, black = (255, 255, 255), (0, 0, 0)

    def process_living(cells):
        for (x1, y1) in cells:
            for x_add, y_add in itertools.permutations(xrange(4), 2):
                p(screen, x1 * scale + x_add, y1 * scale + y_add, white)

    pygame.init()
    screen = pygame.display.set_mode((x * scale, y * scale))

    # game loop
    while True:
        pygame.display.flip()
        pygame.display.get_surface().fill(black)
        process_living(cells)
        engine.tick(cells)
Example #3
0
def pyglet_way():
    rows, cols = 100, 100

    cells = engine.randomized_cells((rows,cols))

    scale = 4
    red = 1.0, 0, 0, 1.0
    colors = {
        'red'         : (1.0,    0,      0,      1.0),
        'gray20'      : (0.2,    0.2,    0.2,    1.0),
        'whitesmoke'  : (0.9607, 0.9607, 0.9607, 1.0),
        'lightsalmon' : (1.0,    0.6275, 0.4784, 1.0)
    }

    window = pyglet.window.Window(width=cols*scale, height=rows*scale)
    pyglet.gl.glClearColor(*colors['gray20'])
    pyglet.gl.glColor4f(*colors['whitesmoke'])

    gl_flag, indices = 'v2i', (0, 1, 2, 0, 2, 3)

    def draw_square(point, size):
        x, y = point[1] * size, (rows - point[0]) * size
        x_size, y_size = x+size, y+size
        vertices = x,y, x_size,y, x_size,y_size, x,y_size
        pyglet.graphics.draw_indexed(4, pyglet.gl.GL_TRIANGLES, indices, (gl_flag, vertices))

    def process_living(cells):
        for point in cells:
            draw_square(point, scale)

    def on_draw(self):
        #callback needs self
        window.clear()
        process_living(cells)
        engine.tick(cells)

    pyglet.clock.schedule(on_draw)
    pyglet.app.run()