TinyCircuits / TinyCircuits-Thumby-Code-Editor

https://code.thumby.us/
GNU General Public License v3.0
30 stars 20 forks source link

Add 3x5 font #21

Closed ultrasuperpingu closed 2 years ago

ultrasuperpingu commented 2 years ago

The proposed fonts are a bit large for such a tiny screen. I made this smaller font.

ultrasuperpingu commented 2 years ago

Do you think this font is not a good idea for the thumby? If you think so, just close this PR, no problem. I just wanted to share this and I thought it was easier if the font was included in the framework but it's not a problem if it's not. I'm not sure to have time to do it but I'd like to try to handle variable width characters in fonts. I'd like to handle ISO 8859-1 characters too. If I implement that, do you think you will include it?

ghost commented 2 years ago

Sorry it took so long to get to this.

Looks good to me!

Here's the code I used to test:

import thumby

thumby.display.fill(0)

thumby.display.setFont("/lib/font3x5.bin", 3, 5, 1)
thumby.display.drawText("ABCDEFGHIJKLMNOPQ", 0, 0, 1)
thumby.display.drawText("RSTUVWXYZ", 0, 6, 1)

thumby.display.update()

while(1):
    pass

This may end up on the firmware that gets uploaded to every device.

ultrasuperpingu commented 2 years ago

If you want to test every characters, I have tested with this:

import thumby

thumby.display.fill(1)
thumby.display.setFont("/lib/font3x5.bin", 3, 5, 1)
thumby.display.drawText("abcdefghijklmnopqr", 0, 0, 0)
thumby.display.drawText("stuvwxyzABCDEFGHIJ", 0, 6, 0)
thumby.display.drawText("KLMNOPQRSTUVWXYZ01", 0, 12, 0)
thumby.display.drawText("23456789&\"'([-|`_\\", 0, 18, 0)
thumby.display.drawText("^@)]=}+$*%!:/;,?.<", 0, 24, 0)
thumby.display.drawText("> I need beer man", 0, 30, 0)
thumby.display.update()

while(1):
    pass
ultrasuperpingu commented 2 years ago

If somebody want to customize this, here is the image file of the font: font3x5_line and the code I made to generate the font file (C#):

using System.Drawing;

Bitmap img = new Bitmap("font3x5_line.png");
byte[] bitmap = new byte[96*3];
for(int i=32;i<128;i++)
{
    int index = (i-32)*3;
    if (img.GetPixel(i*3, 0).R==0)
        bitmap[index] |= 1;
    if (img.GetPixel(i*3, 1).R==0)
        bitmap[index] |= 2;
    if (img.GetPixel(i*3, 2).R==0)
        bitmap[index] |= 4;
    if (img.GetPixel(i*3, 3).R==0)
        bitmap[index] |= 8;
    if (img.GetPixel(i*3, 4).R==0)
        bitmap[index] |= 16;
    if (img.GetPixel(i*3+1, 0).R==0)
        bitmap[index+1] |= 1;
    if (img.GetPixel(i*3+1, 1).R==0)
        bitmap[index+1] |= 2;
    if (img.GetPixel(i*3+1, 2).R==0)
        bitmap[index+1] |= 4;
    if (img.GetPixel(i*3+1, 3).R==0)
        bitmap[index+1] |= 8;
    if (img.GetPixel(i*3+1, 4).R==0)
        bitmap[index+1] |= 16;
    if (img.GetPixel(i*3+2, 0).R==0)
        bitmap[index+2] |= 1;
    if (img.GetPixel(i*3+2, 1).R==0)
        bitmap[index+2] |= 2;
    if (img.GetPixel(i*3+2, 2).R==0)
        bitmap[index+2] |= 4;
    if (img.GetPixel(i*3+2, 3).R==0)
        bitmap[index+2] |= 8;
    if (img.GetPixel(i*3+2, 4).R==0)
        bitmap[index+2] |= 16;
}
var f = File.OpenWrite("font3x5.bin");
f.Write(bitmap);
f.Close();
ultrasuperpingu commented 2 years ago

It's still not working on the current version. Is it deployed or is it missing something ?

ghost commented 2 years ago

It is added to update now. I'll still need to add it to the firmware that gets uploaded to each Thumby.