Exemple #1
0
def main():
    img_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'images', 'balloon.png'))
    balloon = Image.open(img_path) \
        .transform(device.size, Image.AFFINE, (1, 0, 0, 0, 1, 0), Image.BILINEAR) \
        .convert("L") \
        .convert(device.mode)

    while True:
        # Image display
        device.display(balloon)
        device.display(balloon)
        time.sleep(5)

        # Greyscale
        shades = 16
        w = device.width / shades
        for _ in range(2):
            with canvas(device, dither=True) as draw:
                for i, color in enumerate(range(0, 256, shades)):
                    rgb = (color << 16) | (color << 8) | color
                    draw.rectangle((i * w, 0, (i + 1) * w, device.height),
                                   fill=rgb)

                size = draw.textsize("greyscale")
                left = (device.width - size[0]) // 2
                top = (device.height - size[1]) // 2
                right = left + size[0]
                bottom = top + size[1]
                draw.rectangle((left - 1, top, right, bottom), fill="black")
                draw.rectangle(device.bounding_box, outline="white")
                draw.text((left, top), text="greyscale", fill="white")

        time.sleep(5)
def main():
    elapsed_time = 0
    count = 0
    print("Testing OLED dislay rendering performance")
    print("Press Ctrl-C to abort test\n")

    image = Image.new(device.mode, device.size)
    draw = ImageDraw.Draw(image)
    demo.primitives(draw)

    for i in range(5, 0, -1):
        sys.stdout.write("Starting in {0} seconds...\r".format(i))
        sys.stdout.flush()
        time.sleep(1)

    try:
        while True:
            with Timer() as t:
                device.display(image)

            elapsed_time += t.interval
            count += 1

            if count % 31 == 0:
                avg_transit_time = elapsed_time * 1000 / count
                avg_fps = count / elapsed_time

                sys.stdout.write(
                    "#### iter = {0:6d}: render time = {1:.2f} ms, frame rate = {2:.2f} FPS\r"
                    .format(count, avg_transit_time, avg_fps))
                sys.stdout.flush()

    except KeyboardInterrupt:
        del image
Exemple #3
0
def main():
    img_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'images', 'balloon.png'))
    balloon = Image.open(img_path) \
        .transform(device.size, Image.AFFINE, (1, 0, 0, 0, 1, 0), Image.BILINEAR) \
        .convert(device.mode)

    while True:
        # Image display
        device.display(balloon)
        time.sleep(5)

        # Cycle through some primary colours
        for color in [
                "black", "white", "red", "orange", "yellow", "green", "blue",
                "indigo", "violet"
        ]:
            with canvas(device) as draw:
                draw.rectangle(device.bounding_box, fill=color)
                size = draw.textsize(color)
                left = (device.width - size[0]) / 2
                top = (device.height - size[1]) / 2
                right = left + size[0]
                bottom = top + size[1]
                draw.rectangle((left - 1, top, right, bottom), fill="black")
                draw.text((left, top), text=color, fill="white")

            time.sleep(3)

        # Rainbow
        w = 4
        with canvas(device) as draw:
            for i in range(device.width / w):
                r = int(math.sin(0.3 * i + 0) * 127) + 128
                g = int(math.sin(0.3 * i + 2) * 127) + 128
                b = int(math.sin(0.3 * i + 4) * 127) + 128
                rgb = (r << 16) | (g << 8) | b
                draw.rectangle((i * w, 0, (i + 1) * w, device.height),
                               fill=rgb)
        time.sleep(5)

        # Random blocks
        w = device.width / 12
        h = device.height / 8
        for _ in range(40):
            with canvas(device) as draw:
                for x in range(12):
                    for y in range(8):
                        color = random.randint(0, 2**24)
                        left = x * w
                        right = (x + 1) * w
                        top = y * h
                        bottom = (y + 1) * h
                        draw.rectangle((left, top, right - 2, bottom - 2),
                                       fill=color)

                time.sleep(0.25)
Exemple #4
0
def main():
    with canvas(device) as draw:
        draw.multiline_text(offset, "Please do\nnot adjust\nyour set", fill="white", align="center", spacing=-1)

    images = [snow() for _ in range(20)]
    while True:
        random.shuffle(images)
        for background in images:
            device.display(background)
Exemple #5
0
def main():
    print("Testing basic canvas graphics...")
    image = Image.new('1', (device.width, device.height))
    draw = ImageDraw.Draw(image)
    demo.primitives(draw)

    for i in range(1000):
        with Timer() as t:
            device.display(image)
        print("{0}: time = {1} s".format(i, t.interval))

    del image
Exemple #6
0
def main():
    img_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'images', 'pi_logo.png'))
    logo = Image.open(img_path).convert("RGBA")
    fff = Image.new(logo.mode, logo.size, (255, ) * 4)

    background = Image.new("RGBA", device.size, "white")
    posn = ((device.width - logo.width) // 2, 0)

    while True:
        for angle in range(0, 360, 2):
            rot = logo.rotate(angle, resample=Image.BILINEAR)
            img = Image.composite(rot, fff, rot)
            background.paste(img, posn)
            device.display(background.convert(device.mode))
Exemple #7
0
    if device.size not in ((128, 64), (96, 64)):
        raise ValueError("Unsupported mode: {0}x{1}".format(
            device.width, device.height))

    plyr = player()
    army = army()
    rows = random.sample(range(12), 12)

    img_path = os.path.abspath(
        os.path.join(os.path.dirname(__file__), 'images', 'splash.bmp'))
    splash = Image.open(img_path) \
        .transform((device.width, device.height), Image.AFFINE, (1, 0, 0, 0, 1, 0), Image.BILINEAR) \
        .convert(device.mode)

    # Double buffering in pygame?
    device.display(splash)
    device.display(splash)

    time.sleep(3)
    device.clear()

    while not army.invaded and army.size() > 0:
        with canvas(device) as draw:
            draw.line((0, 61, 95, 61), fill="white")
            draw.line((0, 63, 95, 63), fill="white")

            ai_logic_shoot(army, plyr)
            ai_logic_move(army, plyr, rows)

            army.update(plyr.bullets)
Exemple #8
0
    fps += 1
    if fps_time < time.time():
        fps_time += 1
        if gstreamer_running:
            print(' fps %i' % fps)
        fps = 0
        gstreamer_running = True

    if args.video or args.url:
        threshold = 0
        for t in range(0, data_size, data_size // 100):
            threshold += int(data[t])
        threshold //= 100
        sys.stderr.write('\rthreshold %i  ' % threshold)

    image = bytearray(data_size // 8)

    for i in range(0, data_size, 8):
        image[i // 8] = ((data[i + 0] > threshold) and 0x80) | \
                        ((data[i + 1] > threshold) and 0x40) | \
                        ((data[i + 2] > threshold) and 0x20) | \
                        ((data[i + 3] > threshold) and 0x10) | \
                        ((data[i + 4] > threshold) and 0x08) | \
                        ((data[i + 5] > threshold) and 0x04) | \
                        ((data[i + 6] > threshold) and 0x02) | \
                        ((data[i + 7] > threshold) and 0x01)

    image = Image.frombytes("1", device.size, bytes(image))
    device.display(image)