我有一个实验室作业,应该在我的raspberry pi v.4的gfxhat上模拟一个Etch-a-Sketch机器,但是我不知道从哪里开始。我在提供的模板下方发布了内容,但我不知道下一步该怎么做,我们将不胜感激。
from gfxhat import lcd, fonts
from PIL import Image, ImageFont, ImageDraw
def clearScreen(lcd):
lcd.clear()
lcd.show()
def displayText(text,lcd,x,y):
lcd.clear()
width, height = lcd.dimensions()
image = Image.new('P', (width, height))
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(fonts.AmaticSCBold, 24)
w, h = font.getsize(text)
draw.text((x,y), text, 1, font)
for x1 in range(x,x+w):
for y1 in range(y,y+h):
pixel = image.getpixel((x1, y1))
lcd.set_pixel(x1, y1, pixel)
lcd.show()