hello.py

../_images/hello.jpg

Test for text_font_converter.

Writes “Hello!” in random colors at random locations on the Display. https://www.youtube.com/watch?v=atBa0BYPAAc

Note

This example requires the following modules:

  • st7789py

  • tft_config

  • vga2_bold_16x32

 1"""
 2hello.py
 3========
 4
 5.. figure:: ../_static/hello.jpg
 6    :align: center
 7
 8    Test for text_font_converter.
 9
10Writes "Hello!" in random colors at random locations on the Display.
11https://www.youtube.com/watch?v=atBa0BYPAAc
12
13.. note:: This example requires the following modules:
14
15  .. hlist::
16    :columns: 3
17
18    - `st7789py`
19    - `tft_config`
20    - `vga2_bold_16x32`
21
22"""
23
24import random
25import st7789py as st7789
26import tft_config
27import vga2_bold_16x32 as font
28
29
30def main():
31    """
32    The big show!
33    """
34    tft = tft_config.config(tft_config.WIDE)
35
36    while True:
37        for rotation in range(4):
38            tft.rotation(rotation)
39            tft.fill(0)
40            col_max = tft.width - font.WIDTH * 5
41            row_max = tft.height - font.HEIGHT
42            if col_max < 0 or row_max < 0:
43                raise RuntimeError(
44                    "This font is too big to display on this screen."
45                )
46
47            for _ in range(100):
48                tft.text(
49                    font,
50                    "Hello",
51                    random.randint(0, col_max),
52                    random.randint(0, row_max),
53                    st7789.color565(
54                        random.getrandbits(8),
55                        random.getrandbits(8),
56                        random.getrandbits(8),
57                    ),
58                    st7789.color565(
59                        random.getrandbits(8),
60                        random.getrandbits(8),
61                        random.getrandbits(8),
62                    ),
63                )
64
65
66main()