在 CircuitPython 中使用 displayio 查看幻灯片(带有演示代码)—— Twitter 。
在 CircuitPython 中使用 displayio 查看幻灯片
- shaoziyang
- 帖子: 3954
- 注册时间: 2019年 10月 21日 13:48
Re: 在 CircuitPython 中使用 displayio 查看幻灯片
代码
代码: 全选
# 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)
-
- 随机主题
- 回复总数
- 阅读次数
- 最新文章
-
- 1回复总数
- 751 阅读次数
- 最新文章 由 shaoziyang
2021年 9月 1日 11:11
-
- 1回复总数
- 971 阅读次数
- 最新文章 由 shaoziyang
2021年 9月 1日 11:25
-
- 7回复总数
- 1389 阅读次数
- 最新文章 由 zwjiang
2021年 9月 2日 09:05