Example #1
0
def test_tile_intersection_slices():
    master = Tile((0, 0), (640, 400))
    tile = Tile((100, 100), (100, 300))

    blue = np.array([(0, 0, 153, 255)], dtype=Pixel)
    red = np.array([(153, 0, 0, 255)], dtype=Pixel)
    white = np.array([(255, 255, 255, 255)], dtype=Pixel)

    master.buffer[::] = white
    tile.buffer[::] = red

    m, t = master.intersection_slices(tile)
    master.buffer[m] = tile.buffer[t]

    save_array_as_image('test_tile_2.tiff', master.buffer, 'RGBA')
Example #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')
Example #3
0
def blocktopus():
    import random
    import math
    r = random.SystemRandom()

    mode = 'RGBA'
    image_shape = (1280, 960)
    # image_shape = (640, 480)

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

    colors = {
        'white'        : '#ffff',
        'black'        : '#000f',
        '205A8C'       : '205A8C',
        '6596BF'       : '6596BF',
        '98F2EC'       : '98F2EC',
        'BF6865'       : 'BF6865',
        'F4DBD6'       : 'F4DBD6',
        'dark_blue'    : '05115B',
        'light_blue'   : '60CAF0',
        'brown_yellow' : 'DAB32B',
        'brown'        : '855E14',
        'yellow'       : 'FFDD06',
    }

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

    def make_tile(color):
        tile = Tile((0, 0), (16, 16))
        tile.buffer[:] = color
        return tile

    blocktopus_colors = (
        'brown',
        'brown_yellow',
        'dark_blue',
        'light_blue',
        'yellow',
    )

    tiles = { }

    def get_tile(tile_id):
        tile = tiles.get(tile_id)
        if tile is not None:
            return tile
        
        color = r.choice(blocktopus_colors)
        tiles[tile_id] = out = make_tile(color)
        out.buffer[:] = colors[color]
        return out

    spine = Line(
        point(.1 * image_shape[0], .5 * image_shape[1]),
        point(.9 * image_shape[0], .5 * image_shape[1])
    )

    direction = normalize(spine.direction)
    up = normalize(rotate_left(spine.direction))

    steps = 30 
    step_size = 1. / steps
    frequency = 2.5 * 2. * math.pi * step_size

    frames = 10 * 30

    for frame in range(frames):
        image.buffer[:] = colors['white']

        phase = 2 * 2. * math.pi * frame / frames
        phase_offset = .5 - math.cos(phase)

        for i in range(steps):
            width_factor = (1. - float(i) / (steps - 1))
            width = width_factor * .15 * image_shape[1]

            s = math.cos(frequency * i + phase) + phase_offset

            base = spine(i * step_size)

            offsets = [
                s * width * up,
                (s - 1) * width * up,
            ]

            for (j, offset) in enumerate(offsets):
                p = base + offset
                tile = get_tile((i, j))
                tile.set_origin(p[:2])

                intersection = image.intersection_slices(tile)
                if intersection is None: continue

                m, t = intersection
                image.buffer[m] = tile.buffer[t]

        path = 'blocktopus/frame_{frame:03}.tiff'.format(frame=frame)
        save_array_as_image(path, image.buffer, 'RGBA')