font454.py — a tiny 4x5 pixel antialiased font for low-resolution displays
font454.py — a tiny 4x5 pixel antialiased font for low-resolution displays
Hello micro pythonistas!
MicroPython's famebuf module comes with a built-in font which is fine most of the time, but not always suitable for all use cases. For one, it's pretty large, at 8x8 pixels per character, furthermore, it's monochrome. With microcontrollers, we often have to deal with low-resolution displays, such as small OLED modules or LED matrices. It would be nice to have a font that is smaller and more legible at small sizes.
So I designed this font: https://bitbucket.org/thesheep/font454/src
The characters are only 4×6 pixels (and most of them are actually 5 pixels high), and the font has 4 colors, which you can set while rendering it. The rendering works on any object that has a "pixel" method that takes x, y and color — so you can use a framebuf or a display directly.
I have drawn the letters by hand, trying to make them look friendly (since I'm using them for a game console project), but also legible — that means large x-height, squarish shapes, etc. It contains all standard ASCII characters.
The repository also contains the image and code used to generate the font, and a simple test program that generates the above PNG file. It requires pygame and python3 to run.
MicroPython's famebuf module comes with a built-in font which is fine most of the time, but not always suitable for all use cases. For one, it's pretty large, at 8x8 pixels per character, furthermore, it's monochrome. With microcontrollers, we often have to deal with low-resolution displays, such as small OLED modules or LED matrices. It would be nice to have a font that is smaller and more legible at small sizes.
So I designed this font: https://bitbucket.org/thesheep/font454/src
The characters are only 4×6 pixels (and most of them are actually 5 pixels high), and the font has 4 colors, which you can set while rendering it. The rendering works on any object that has a "pixel" method that takes x, y and color — so you can use a framebuf or a display directly.
I have drawn the letters by hand, trying to make them look friendly (since I'm using them for a game console project), but also legible — that means large x-height, squarish shapes, etc. It contains all standard ASCII characters.
The repository also contains the image and code used to generate the font, and a simple test program that generates the above PNG file. It requires pygame and python3 to run.
Re: font454.py — a tiny 4x5 pixel antialiased font for low-resolution displays
Nice job!
Thanks for putting in the effort... it was well worth it.
Thanks for putting in the effort... it was well worth it.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: font454.py — a tiny 4x5 pixel antialiased font for low-resolution displays
Well done. At small sizes there's no substitute for hand designed bitmapped fonts.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: font454.py — a tiny 4x5 pixel antialiased font for low-resolution displays
Thanks for the picture bitninja !
It appears that Deshipu has done an incredible job (yet again), but it appears a lot more clearly in your real-life example
It appears that Deshipu has done an incredible job (yet again), but it appears a lot more clearly in your real-life example
Re: font454.py — a tiny 4x5 pixel antialiased font for low-resolution displays
Sure!fpp wrote:Thanks for the picture bitninja !
It appears that Deshipu has done an incredible job (yet again), but it appears a lot more clearly in your real-life example
With font454.py, I am able to squeeze 32 characters of text on 10 lines on a 128x64 OLED display. The results are pretty awesome...
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: font454.py — a tiny 4x5 pixel antialiased font for low-resolution displays
It amuses me that my efforts were in the opposite direction: using larger fonts. A sign of what happens to your eyesight with advancing years
https://github.com/peterhinch/micropyth ... sd1306.JPG
https://github.com/peterhinch/micropyth ... sd1306.JPG
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Using your font on a Nokia 5110 PCD8544 84x48 LCD
Hello deshipu,
could you explain better what are the 4 colors for and if they are needed on a monochromatic display?
I'd like to use your font on a Nokia 5110 PCD8544 84x48 LCD. It comes really in hando with only 84 x 48 pixels.
As is it works out of the box, rendering black text on white or white text on black, however I wonder if the antialiasing can be stripped out on a monochromatic display -- and what I should remove.
Thanks for your help
Re: Using your font on a Nokia 5110 PCD8544 84x48 LCD
It can be used for anti-aliasing when your display has more than 2 colors/shades available, and for making the font look heavier/lighter when it only has 1-bit display. Basically, if you make it 0-1-1-1 then it will look heavy, with all corners squared off, and with 0-0-0-1 it will be lightweight, with all corners diagonal. 0-0-1-1 will give you rounded corners.