https://github.com/benders/micropython-pixelfonts
Very small bitmap fonts for use with MicroPython
https://github.com/benders/micropython-pixelfonts
micropython
Last synced: about 1 month ago
JSON representation
Very small bitmap fonts for use with MicroPython
- Host: GitHub
- URL: https://github.com/benders/micropython-pixelfonts
- Owner: benders
- License: cc0-1.0
- Created: 2025-09-09T22:21:36.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2025-09-09T22:38:55.000Z (10 months ago)
- Last Synced: 2025-09-10T02:16:34.620Z (10 months ago)
- Topics: micropython
- Language: Python
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pixelfont
## Usage
```python
from pixelfonts import Font3x5, Font4x7
# Create a font renderer with your display dimensions and pixel function
font = Font3x5(display_width=16, display_height=8, pixel_func=set_pixel)
# Draw text at a specific position
font.text("123", x_offset=0, y_offset=0, color=(255, 255, 255))
# Draw a single character
font.draw_char("5", x_offset=10, y_offset=2, color=(255, 0, 0))
```
### Integration with Display Libraries
pixelfont works with any display library that provides a pixel-setting function. The pixel function should accept x and y coordinates followed by any additional parameters (like color).
```python
# Example with a generic display library
def set_my_pixel(x, y, color):
my_display.pixel(x, y, color)
font = Font4x7(128, 64, set_my_pixel)
font.text("0123", 10, 10, (255, 255, 255))
```
## Available Fonts
- **Font3x5**: A compact 3x5 pixel font, for very small displays
- **Font4x7**: A more readable 4x7 pixel font
## Creating Custom Fonts
You can create your own custom fonts by subclassing `BaseFont`:
```python
from pixelfont import BaseFont
class MyCustomFont(BaseFont):
WIDTH = 5
HEIGHT = 8
FONT = {
"A": [
" # ",
" # # ",
"# #",
"#####",
"# #",
"# #",
"# #",
" "
],
# Add more characters...
}
```