-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.py
36 lines (30 loc) · 1.3 KB
/
util.py
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
"""This module contains helper methods for the handling of flipdotdisplays.
"""
import pygame
pygame.font.init()
def draw_surface_on_fdd(surface: pygame.Surface, flipdotdisplay):
"""Draw the surface onto the display. You need to invoke show()
afterwards to make it visible. Black pixels (rgb 0,0,0) are considered
black and turned off, other colors are considered pixels turned on.
The clipping area of the surface can be modified to draw only part
of the surface. A demo application is available in
demos.PygameSurfaceDemo."""
cx, cy, cw, ch = surface.get_clip()
for y in range(ch):
for x in range(cw):
r, g, b, a = surface.get_at((cx + x, cy + y))
ison = not (r == g == b == 0)
flipdotdisplay.px(x, y, ison)
def draw_text_on_fdd(text, fontname, fontsize, flipdotdisplay):
"""Draw text on a display.
>>> import net
>>> import util
>>> fdd = net.RemoteDisplay("taylorpi.local")
Remote display will send data to taylorpi.local on port 10101
>>> util.draw_text_on_fdd("Hallo", "Arial", 9, fdd)
>>> fdd.show()
"""
font = pygame.font.SysFont(fontname, fontsize, bold=False, italic=False)
surf = font.render(text, False, (255, 255, 255),
None)
draw_surface_on_fdd(surf, flipdotdisplay)