forked from xadacka/led-matrix-controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpithon.py
executable file
·52 lines (39 loc) · 1.6 KB
/
pithon.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#from __future__ import unicode_literals
import emoji
import os
import scrolltext
#from PIL import ImageFont
#from PIL import Image
#from PIL import ImageDraw
from PIL import Image, ImageDraw, ImageFont, ImageFilter
#f = open("/home/pi/led-matrix-controller/rpi-rgb-led-matrix/examples-api-use/scrolltext.txt")
#print(f.read())
text = scrolltext.text
#basic san serif font
#font = ImageFont.truetype("/usr/share/fonts/truetype/freefont/FreeSans.ttf", 16)
#american captain, default font
font = ImageFont.truetype("/home/pi/led-matrix-controller/rpi-rgb-led-matrix/examples-api-use/americancaptain.ttf", 16)
#more styalized
#font = ImageFont.truetype("/home/pi/led-matrix-controller/rpi-rgb-led-matrix/examples-api-use/TooMuchInk.ttf", 16)
#pretty but no numbers and doesn't scale as well
#font = ImageFont.truetype("/home/pi/led-matrix-controller/rpi-rgb-led-matrix/examples-api-use/hellovetica.ttf", 10)
all_text = ""
for text_color_pair in text:
t = text_color_pair[0]
all_text = all_text + t
print(all_text)
width, ignore = font.getsize(all_text)
print(width)
im = Image.new("RGB", (width + 30, 16), "black")
draw = ImageDraw.Draw(im)
x = 0;
for text_color_pair in text:
t = text_color_pair[0]
c = text_color_pair[1]
print("t=" + t + " " + str(c) + " " + str(x))
draw.text((x, 0), t, c, font=font)
x = x + font.getsize(t)[0]
im.save("/home/pi/led-matrix-controller/rpi-rgb-led-matrix/examples-api-use/test.ppm")
os.system("/home/pi/led-matrix-controller/rpi-rgb-led-matrix/examples-api-use/demo -D 1 test.ppm --led-rows=16 --led-chain=4")