接上次的帖子,
https://forum.eepw.com.cn/thread/401710/1
要做一个数据显示的界面,需要折线滑动效果,有界面显示标题,
简单配置后,效果如下:
import board import displayio import math import time import terminalio from adafruit_display_text import label display = board.DISPLAY WIDTH = display.width # 240 HEIGHT = display.height # 135 # ========== 画布 ========== group = displayio.Group() bitmap = displayio.Bitmap(WIDTH, HEIGHT, 2) palette = displayio.Palette(2) palette[0] = 0x000000 # 背景(黑) palette[1] = 0x00FF00 # 波形(绿) tile = displayio.TileGrid(bitmap, pixel_shader=palette) group.append(tile) # ========== 添加文字标签 "HI EEPW!" ========== text = "HI EEPW!" text_label = label.Label(terminalio.FONT, text=text, color=0xFFFFFF) # 白色文字 # 居中显示在屏幕上方 text_label.anchored_position = (WIDTH // 2, 20) text_label.anchor_point = (0.9, 0.9) group.append(text_label) display.root_group = group # ========== 参数 ========== amplitude = 10 center_y = HEIGHT // 2 step = 0.3 # 每列相位步进 phase = 0.0 SHIFT = 1 # 每帧左移列数 DRAW = 1 # 每帧在最右端补画的点数(越大越密) while True: # 1) 整屏向左平移 SHIFT 列(丢弃最左的 SHIFT 列) for x in range(WIDTH - SHIFT): for y in range(HEIGHT): bitmap[x, y] = bitmap[x + SHIFT, y] # 2) 清空最右端 DRAW 列(避免残留) for x in range(WIDTH - DRAW, WIDTH): for y in range(HEIGHT): bitmap[x, y] = 0 # 3) 在右侧补画 DRAW 个连续点,形成较密的波 for k in range(DRAW): x = WIDTH - DRAW + k yy = int(center_y - amplitude * math.sin(phase + x * step)) yy = max(0, min(HEIGHT - 1, yy)) bitmap[x, yy] = 1 phase += step * SHIFT display.refresh() time.sleep(0.005)

我要赚赏金
