-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·154 lines (136 loc) · 3.75 KB
/
example.py
File metadata and controls
executable file
·154 lines (136 loc) · 3.75 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/env python3
import time
import pygame
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import lcd
pygame.mixer.init()
image = []
sounds = {
"tink": "sounds/Tink.aiff.wav",
"ow": "sounds/Basso.aiff.wav",
"submarine": "sounds/Submarine.aiff.wav"
}
def play(sound):
pygame.mixer.music.set_volume(0.08)
pygame.mixer.music.load(sounds[sound])
pygame.mixer.music.play()
while pygame.mixer.music.get_busy() == True:
continue
def load_image():
global image
img = mpimg.imread('images/greg.png')
s = ""
pow=256
for j in range(0,128):
byte = 0
line = []
for i in range(0, 320):
col = i + 40
row = j + 100
k = not int((img[row][col][0]+img[row][col][1]+img[row][col][2])/3)
pow = pow / 2
byte += int(k * pow)
if pow == 1:
x=int((i-7)/8)
line.append(byte)
pow = 256
byte = 0
# print(s)
image.append(line)
# imgplot = plt.imshow(img)
# plt.show()
image = image[::-1]
def print_image():
for col in range(0,40):
s=""
for row in range(0,128):
s += "("+str(row)+","+str(col)+","+str(image[row][col])+")"
print(s)
def box(x0, y0, x1, y1, pixel=1):
for y in range(y0, y1+1):
lcd.set_pixel(x0, y, pixel)
for x in range(x0, x1+1):
lcd.set_pixel(x, y1, pixel)
for y in range(y1, y0-1, -1):
lcd.set_pixel(x1, y, pixel)
for x in range(x1, x0-1, -1):
lcd.set_pixel(x, y0, pixel)
def hline(x0, y0, x1, y1, pixel=1):
for x in range(x0, x1+1):
lcd.set_pixel(x, y0, pixel)
def image_example():
global image
load_image()
lcd.clear_screen(0x55, 0xaa)
play("tink")
lcd.display_image(image)
play("tink")
def box_example():
lcd.clear_screen(0x55, 0xaa)
play("tink")
box(10,10,310,120, 0)
play("tink")
def hline_example():
lcd.defer(True)
lcd.clear_screen(0x55, 0xaa)
play("tink")
for y in range(127, -1, -1):
hline(0, y, 319, 0, 0)
lcd.defer(False)
play("tink")
def text_example():
for y in range(0, 120, 8):
lcd.clear_screen()
lcd.print_at(y, y, "Hello World!")
time.sleep(0.5)
lorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
shortLorem = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do e"
def proportional_text_example():
lcd.defer(True)
lcd.clear_screen()
x = 0
y = 0
h = 12
uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
lowers = "abcdefghijklmnopqrstuvwxyz"
symbols = "0123456789!@#$%^&*(){}[]|\\<>?,./:;'\"-~`=_+"
lcd.print_at(x, y, uppers)
y += h
lcd.print_at(x, y, uppers, 5)
y += h
lcd.print_at(x, y, uppers, 0)
y += h
lcd.print_at(x, y, lowers)
y += h
lcd.print_at(x, y, lowers, 5)
y += h
lcd.print_at(x, y, lowers, 0)
y += h
lcd.print_at(x, y, symbols)
y += h
lcd.print_at(x, y, symbols, 5)
y += h
lcd.print_at(x, y, symbols, 0)
lcd.defer(False)
def lorem_example():
longLorem = lorem+lorem+lorem
lcd.defer(True)
lcd.clear_screen()
y=120
x=0
for i in range(0, len(longLorem), 64):
lcd.print_at(x, y, longLorem[i:i+64], 0)
y -= 8
if y<0: break
lcd.defer(False)
def main():
lcd.setup(0,True)
# image_example()
# box_example()
# hline_example()
proportional_text_example()
# lorem_example()
lcd.teardown()
play("submarine")
main()