Skip to content
Snippets Groups Projects
Commit c0479b40 authored by Jan Luebbe's avatar Jan Luebbe
Browse files

Add python font rendering and an example clock

parent 73418556
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/python
import font_client
from datetime import datetime
import dateutil.tz
while True:
#font_client.draw(datetime.now().isoformat(), points=30)
font_client.draw(datetime.now(dateutil.tz.tzlocal()).isoformat(), points=25)
#!/usr/bin/python
import sys, client
import pygame
pygame.init()
screen = pygame.Surface((client.WIDTH, client.HEIGHT), depth=8)
def send(screen):
w = screen.get_width()
h = screen.get_height()
pxarray = pygame.PixelArray(screen)
pixels = []
for y in range(h):
for x in range(w):
pixels.append(pxarray[x][y])
del pxarray
client.blit(0, 0, w, h, pixels)
prev_mx = None
font = None
def draw(text, mark=None, points=None):
global prev_mx, font
points = points if points else 35 if mark else 60
font = pygame.font.SysFont("DejaVu Sans Mono", points, bold=True)
count = len(text)
text = font.render(text, True, (255, 255, 255), (0, 0, 0))
screen.set_palette(text.get_palette())
screen.fill((0, 0, 0))
w = text.get_width()
h = text.get_height()
x = (client.WIDTH-w)/2
y = (client.HEIGHT-h)/2
if mark:
cw = w/count
mx = x+cw*(mark+0.5)
if not mx == prev_mx:
for size in range(240, 5, -15):
pygame.draw.line(screen, 255,
(mx, 0),
(mx, client.HEIGHT-1),
size)
send(screen)
pygame.draw.line(screen, 0,
(mx, 0),
(mx, client.HEIGHT-1),
size)
prev_mx = mx
pygame.draw.line(screen, 255,
(mx, 0),
(mx, client.HEIGHT-1),
5)
screen.blit(text, (x, y))
send(screen)
if __name__=="__main__":
if len(sys.argv) >= 3:
text = sys.argv[2].decode('utf-8')
else:
text = "Hello World!"
if len(sys.argv) >= 4:
mark = int(sys.argv[3])
else:
mark = None
draw(text, mark)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment