在 CircuitPython 中使用 displayio 查看幻灯片

Adafruit CircuitPython相关
MicroPython重要分支
回复
头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

在 CircuitPython 中使用 displayio 查看幻灯片

#1

帖子 shaoziyang »

在 CircuitPython 中使用 displayio 查看幻灯片(带有演示代码)—— Twitter
图片

头像
shaoziyang
帖子: 3917
注册时间: 2019年 10月 21日 13:48

Re: 在 CircuitPython 中使用 displayio 查看幻灯片

#2

帖子 shaoziyang »

代码

代码: 全选

# slideshow_clear_code.py -- datamosh slideshow viewer using palette transparency tricks
# 2021 @todbot / Tod Kurt 
# https://twitter.com/todbot/status/1461086295439069195
import time, random
import board, displayio
import adafruit_imageload     # via circup

img_fnames = (  # our pictures!  16-color BMP3
    '/pics/img0.bmp',
    '/pics/img1.bmp',
    '/pics/img2.bmp',
)

display = board.DISPLAY

screen = displayio.Group()  # Create a Group to hold content
display.show(screen)  # Add to the Display
screen.append(displayio.Group()) # dummy item put in screen[0] for later
screen.append(displayio.Group()) # dummy item put in screen[1] for later

def load_image(img_num):
    print("loading image", img_num)
    t = screen[0]  # get bottom image
    image, palette = adafruit_imageload.load( img_fnames[img_num] )
    bitmap = displayio.TileGrid(image, pixel_shader=palette)
    screen[0] = bitmap # new image on bottom
    screen[1] = t      # move bottom image to top

img_num = 0
load_image( img_num )

while True:
    img_num = (img_num + 1 ) % len(img_fnames)

    load_image( img_num )
    time.sleep(0.5) # wait a bit so you can see the image
    
    palette = screen[1].pixel_shader
    for i in range(len(palette)):
        palette.make_transparent(i)
        time.sleep(0.01)
 

回复

  • 随机主题
    回复总数
    阅读次数
    最新文章