-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab6_etch_a_sketch.py
More file actions
74 lines (60 loc) · 1.44 KB
/
Copy pathlab6_etch_a_sketch.py
File metadata and controls
74 lines (60 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from gfxhat import lcd, fonts, backlight
from PIL import Image, ImageFont, ImageDraw
import click
import pasi0014 as p
backlight.set_all(255,255,255)
backlight.show()
lcd.clear()
lcd.show()
def clearScreen(lcd):
lcd.clear()
lcd.show()
#Displays text on the gfx hat
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()
displayText("Etch a skretch",lcd,x=20,y=30)
#Etch a Sketch game
r = ''
x=0
y=0
while (r != 'q'):
r=click.getchar()
if ( r == '\x1b[A'):
y=y-1
if(y<0):
y=63
lcd.set_pixel(x,y,1)
lcd.show()
elif ( r == '\x1b[B'):
y=y+1
if (y>63):
y=0
lcd.set_pixel(x,y,1)
lcd.show()
elif ( r == '\x1b[C'):
x=x+1
if(x>127):
x=0
lcd.set_pixel(x,y,1)
lcd.show()
elif ( r == '\x1b[D'):
x=x-1
if (x<0):
x=127
lcd.set_pixel(x,y,1)
lcd.show()
elif( r == 's'):
clearScreen(lcd)
elif( r == 'q'):
clearScreen(lcd)