sprite sheet

This commit is contained in:
Tyrel Souza 2018-08-28 22:04:39 -04:00
parent 7f928ac8be
commit d03b9e5c6d
No known key found for this signature in database
GPG Key ID: 5A9394D4C30AEAC0
2 changed files with 29 additions and 2 deletions

View File

@ -10,6 +10,34 @@ import inkyphat
FAKE = True FAKE = True
text = Image.open("numbers.png")
text_mask = inkyphat.create_mask(text, [inkyphat.WHITE])
def print_digit(position, digit):
"""Print a single digit using the sprite sheet.
Each number is grabbed from the masked sprite sheet,
and then used as a mask to paste the desired color
onto Inky pHATs image buffer.
"""
o_x, o_y = position
num_margin = 2
num_width = 6
num_height = 7
s_x = num_margin + (digit * (num_width + num_margin))
sprite = text_mask.crop((s_x, 0, s_x + num_width, num_height))
inkyphat.paste(inkyphat.WHITE, (o_x, o_y), sprite)
def print_number(position, number):
"""Prints a number using the sprite sheet."""
for digit in str(number):
print_digit(position, int(digit))
position = (position[0] + 8, position[1])
def main(): def main():
pages = {'2014': 7375, '2015': 23508, '2016': 17696, '2017': 19706, '2018': 9388} pages = {'2014': 7375, '2015': 23508, '2016': 17696, '2017': 19706, '2018': 9388}
books = {"2018":33,"2017":64,"2016":47,"2015":75,"2014":19} books = {"2018":33,"2017":64,"2016":47,"2015":75,"2014":19}
@ -89,8 +117,7 @@ def draw_row(row, stats, size):
for year in stats: for year in stats:
count = year[row][0] count = year[row][0]
x,y = year[row][1] x,y = year[row][1]
w, h = font.getsize(count) print_number((x,y), count)
inkyphat.text((x, y), count, inkyphat.WHITE, font)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

BIN
numbers.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB