Skip to content

Instantly share code, notes, and snippets.

@uktechreviews
Created May 27, 2018 23:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uktechreviews/c916e8e64651349085346dab2012d114 to your computer and use it in GitHub Desktop.
Save uktechreviews/c916e8e64651349085346dab2012d114 to your computer and use it in GitHub Desktop.
Pimoroni inkyphat examples
#!/usr/bin/env python
import inkyphat
from random import randint
def draw_text(position, text, font=None, colour=inkyphat.BLACK):
x, y = position
x = x+5
if font is None:
font = inkyphat.ImageFont.truetype(inkyphat.fonts.AmaticSC,20)
w, h = font.getsize(text)
mask = inkyphat.Image.new('1', (w, h))
draw = inkyphat.ImageDraw.Draw(mask)
draw.text((0, 0), text, 1, font)
position = x,y
inkyphat.paste(colour, position, mask)
quotes = open("quotes", "r")
lines = quotes.readlines()
quotes.close()
maximum = len(lines)
choice=(randint(1,maximum))
test = str(lines[choice])
text = [test[i:i+33] for i in range(0,len(test),33)]
for i in range(len(text)):
new_text=text[i]
if (new_text[32:33])!=" ":
new_text=new_text+"-"
if (new_text[-2:-1:])==".":
new_text=new_text[:-1]
text[i]=new_text
try:
draw_text((0,0), str(text[0]), colour=inkyphat.RED)
draw_text((0,20), str(text[1]), colour=inkyphat.BLACK)
draw_text((0,40), str(text[2]), colour=inkyphat.BLACK)
draw_text((0,60), str(text[3]), colour=inkyphat.BLACK)
draw_text((0,80), str(text[4]), colour=inkyphat.BLACK)
except IndexError:
pass
inkyphat.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment