def spin_image(img): '''Display an image on the LCD screen and spin it.''' lcd.pos(4, 24) lcd.puts('Generating frames...') work = img.convert('RGBA') frames = [] for angle in range(0, 360, args.step): lcd.pos(4) lcd.puts('%3s' % (int((angle / 360.0) * 100))) lcd.send_data([0xff] * int(angle / 360.0 * (128 - 24))) x = work.rotate(angle, expand=True) x = x.crop(box=(x.size[0] / 2 - work.size[0] / 2, x.size[1] / 2 - work.size[1] / 2, x.size[0] / 2 + work.size[0] / 2, x.size[1] / 2 + work.size[1] / 2)) mask = Image.new('RGBA', x.size, (255, ) * 4) out = Image.composite(x, mask, x) screen.drawbitmap(out.convert('1'), centerx=True, centery=True) frames.append(screen[:]) while True: for frame in frames: lcd.write_buffer(frame) time.sleep(args.delay)
def spin_image(img): '''Display an image on the LCD screen and spin it.''' lcd.pos(4, 24) lcd.puts('Generating frames...') work = img.convert('RGBA') frames = [] for angle in range(0, 360, args.step): lcd.pos(4) lcd.puts('%3s' % (int((angle/360.0) * 100))) lcd.send_data([0xff] * int(angle/360.0 * (128-24))) x = work.rotate(angle, expand=True) x = x.crop(box=(x.size[0]/2 - work.size[0]/2, x.size[1]/2 - work.size[1]/2, x.size[0]/2 + work.size[0]/2, x.size[1]/2 + work.size[1]/2)) mask = Image.new('RGBA', x.size, (255,) * 4) out = Image.composite(x, mask, x) screen.drawbitmap(out.convert('1'), centerx=True, centery=True) frames.append(screen[:]) while True: for frame in frames: lcd.write_buffer(frame) time.sleep(args.delay)
def hscroll_image(img): '''Display an image on the LCD screen and scroll it horizontally.''' screen.drawbitmap(img, centerx=True, centery=True) while True: screen.hscroll(args.step) lcd.write_buffer(screen) time.sleep(args.delay)
def shift_imgs(screen, lcd): lcd.clear() h = random.randint(-2, 2) v = random.randint(0, 2) shift = (h, v) screen.hscroll(shift[0]) screen.vscroll(shift[1]) lcd.write_buffer(screen) screen.clear()
def display_img(img, screen, lcd, size = 100, x=0, y=0): """ Displays PIL image objects on the ST7565 display at a specified x and y coordinates. `img`: A `PIL` image object. `screen`: A bitmap object. What will be written to the display. `lcd`: An lcd object. """ if not(size == 100): img = resize_image(img, size) try: screen.drawbitmap(img, x, y) lcd.write_buffer(screen) except IndexError: size = img.size print("Image with size (%d,%d) cannot be fit onto (128, 64) size display using given coordinates: (%d,%d)" % (size[0], size[1], x, y))
def display_image(img): '''Display an image on the LCD screen.''' screen.drawbitmap(img, centerx=True, centery=True) lcd.write_buffer(screen)