-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathtiny_hello.py
More file actions
87 lines (69 loc) · 1.96 KB
/
tiny_hello.py
File metadata and controls
87 lines (69 loc) · 1.96 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
"""
tiny_hello.py
=============
.. figure:: ../_static/tiny_hello.jpg
:align: center
Test text_font_converter on small displays.
Writes "Hello!" in a tiny font in random colors at random locations on the Display.
.. note:: This example requires the following modules:
.. hlist::
:columns: 3
- `st7789py`
- `tft_config`
- `vga1_8x8`
"""
import random
import time
import tft_text
import tft_config
palette = tft_config.palette
import vga1_8x8 as font
tft = tft_config.config(tft_config.WIDE)
def center(text, fg=palette.WHITE, bg=palette.BLACK):
"""
Centers the given text on the display.
"""
length = len(text)
tft_text.text(
tft,
font,
text,
tft.width // 2 - length // 2 * font.WIDTH,
tft.height // 2 - font.HEIGHT,
fg,
bg,
)
def main():
"""
The big show!
"""
for color in [palette.RED, palette.GREEN, palette.BLUE]:
tft.draw.fill(color)
tft.draw.rect(0, 0, tft.width, tft.height, palette.WHITE)
center("Hello!", palette.WHITE, color)
time.sleep(1)
while True:
for rotation in range(4):
tft.rotation = rotation
tft.draw.fill(0)
col_max = tft.width - font.WIDTH * 6
row_max = tft.height - font.HEIGHT
for _ in range(128):
tft_text.text(
tft,
font,
"Hello!",
random.randint(0, col_max),
random.randint(0, row_max),
palette.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8),
),
palette.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8),
),
)
main()