hello.py

../_images/hello.png

Writes “Hello!” in random colors at random locations on the display.

 1"""
 2hello.py
 3========
 4
 5.. figure:: /_static/hello.png
 6  :align: center
 7
 8Writes "Hello!" in random colors at random locations on the display.
 9"""
10
11import random
12
13import vga1_bold_16x32 as font
14import gc9a01
15import tft_config
16
17tft = tft_config.config(tft_config.TALL)
18
19
20def main():
21
22    tft.init()
23
24    while True:
25        for rotation in range(4):
26            tft.rotation(rotation)
27            tft.fill(0)
28            col_max = tft.width() - font.WIDTH * 6
29            row_max = tft.height() - font.HEIGHT
30
31            for _ in range(128):
32                tft.text(
33                    font,
34                    "Hello!",
35                    random.randint(0, col_max),
36                    random.randint(0, row_max),
37                    gc9a01.color565(
38                        random.getrandbits(8),
39                        random.getrandbits(8),
40                        random.getrandbits(8),
41                    ),
42                    gc9a01.color565(
43                        random.getrandbits(8),
44                        random.getrandbits(8),
45                        random.getrandbits(8),
46                    ),
47                )
48
49
50main()