Beispiel #1
0
def test_tile():
    tile = Tile((0, 0), (100, 200))

    assert tile.origin == (0, 0)
    assert tile.shape == (100, 200)
    assert tile.horizontal == Interval(0, 100)
    assert tile.vertical == Interval(0, 200)

    tile.set_origin((25, 50))

    assert tile.origin == (25, 50)
    assert tile.shape == (100, 200)
    assert tile.horizontal == Interval(25, 125)
    assert tile.vertical == Interval(50, 250)
Beispiel #2
0
def render_tile():
    import random

    mode = 'RGBA'
    image_shape = (640, 480)

    image = Tile((0,0), image_shape)

    r = random.SystemRandom()

    colors = {
        'white'  : '#ffff',
        'black'  : '#000f',
        '205A8C' : '205A8C',
        '6596BF' : '6596BF',
        '98F2EC' : '98F2EC',
        'BF6865' : 'BF6865',
        'F4DBD6' : 'F4DBD6',
    }

    for name, color in colors.items():
        colors[name] = parse_color(color)

    image.buffer[:,:] = colors['white']

    tile_colors = [ color for name, color in colors.items() if name not in ('black', 'white') ]
    # tile = Tile((0, 0), (100, 100))
    tile = Tile((0, 0), (16, 16))

    for x in range(0, image_shape[0], 16):
        for y in range(0, image_shape[1], 16):
            # x = int(r.random() * image_shape[0])
            # y = int(r.random() * image_shape[1])
            tile.set_origin((x, y))
            tile.buffer[:] = r.sample(tile_colors, 1)

            i, t = image.intersection_slices(tile)
            image.buffer[i] = tile.buffer[t]

    save_array_as_image('test_tile.gif', image.buffer, 'RGBA')