def write_string(string, offset_x=0, offset_y=0, kerning=True):
"""Write a string to the buffer
:returns: The length, in pixels, of the written string.
:param string: The text string to write
:param offset_x: Position the text along x (default 0)
:param offset_y: Position the text along y (default 0)
:param kerning: Whether to kern the characters closely together or display one per matrix (default True)
:Examples:
Write a string to the buffer, aligning one character per dislay, This is
ideal for displaying still messages up to 6 characters long::
microdotphat.write_string("Bilge!", kerning=False)
Write a string to buffer, with the characters as close together as possible.
This is ideal for writing text which you intend to scroll::
microdotphat.write_string("Hello World!")
"""
str_buf = []
space = [0x00] * 5
gap = [0x00] * 3
if kerning:
space = [0x00] * 2
gap = [0x00]
for char in string:
if char == ' ':
str_buf += space
else:
char_data = numpy.array(_get_char(char))
if kerning:
char_data = numpy.trim_zeros(char_data)
str_buf += list(char_data)
str_buf += gap # Gap between chars
for x in range(len(str_buf)):
for y in range(7):
p = (str_buf[x] & (1 << y)) > 0
set_pixel(offset_x + x, offset_y + y, p)
l = len(str_buf)
del str_buf
return l
评论列表
文章目录