sprites.py

Created by valmontechno

Created on April 19, 2025

1.05 KB

This module allows you to display images on the Numworks calculator. You can convert any image with the sprite converter then display it on the calculator with the sprites module.

View GitHub documentation


# Sprites by Valmontechno
# https://github.com/valmontechno/Sprites-Numworks

__name__ = 'sprites'
__version__ = '2.1'

from kandinsky import *

SCREEN_WIDTH = 320
SCREEN_HEIGHT = 222

COLOR_CHAR = 'abcdefghijklmnopqrstuvwxyz'
BLANK_CHAR = '.'
NEWLINE_CHAR = ','

def draw_sprite(sprite, pallet, x, y, scale=(1, 1)):
    if isinstance(scale, (int, float)):
        scale = [scale] * 2
    yPos = y
    for col in sprite.split(NEWLINE_CHAR):
        xPos = x
        factorStr = '0'
        for char in col:
            if char in '0123456789':
                factorStr += char
            else:
                factor = max(int(factorStr), 1)
                if char != BLANK_CHAR:
                    color = pallet[COLOR_CHAR.index(char)]
                    fill_rect(int(xPos), int(yPos), int(scale[0] * factor), int(scale[1]), color)
                xPos += scale[0] * factor
                factorStr = '0'
        yPos += (scale[1] * max(int(factorStr), 1))

def fill_screen(color='#ffffff'):
    fill_rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color)

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.