Skip to content

Instantly share code, notes, and snippets.

@spiikki
Created September 6, 2023 19:15
Show Gist options
  • Save spiikki/0e6dd2586ce7e204fba8d809861d7b54 to your computer and use it in GitHub Desktop.
Save spiikki/0e6dd2586ce7e204fba8d809861d7b54 to your computer and use it in GitHub Desktop.
Font scaler for PIHut Waveshare LCD library
def scaleChar(asc,xt,yt,sz,r,g,b):
cc = colour(r,g,b)
code = asc * 5 # 5 bytes per character
for ii in range(5):
line = FONT[code + ii]
for yy in range(8):
if (line >> yy) & 0x1:
for y in range(sz):
for x in range(sz):
lcd.pixel(ii*sz+xt+x, yy*sz+yt+y,cc)
def prnt_st(asci,xx,yy,sz,r,g,b): # Text string
move = 5*sz+2
for letter in(asci):
asci = ord(letter)
scaleChar(asci,xx,yy,sz,r,g,b)
xx = xx + move
def cntr_st(s,y,sz,r,g,b): # Centres text on line y
w = 5*sz+2
gap = int((240 - len(s) * w)/2) # NOTICE HARDCODE SCREEN SIZE
prnt_st(s,gap,y,sz,r,g,b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment