font to nodered

This commit is contained in:
interfisch 2024-02-25 14:01:53 +01:00
parent a18bb948ec
commit c3564ef7d2
10 changed files with 286 additions and 19 deletions

View File

@ -7,22 +7,46 @@ done = False
persistance=False persistance=False
fps=10 fps=10
color_checkerboardA=(250,250,250)
color_checkerboardB=(200,200,200)
color_bg=(255,255,255)
color_text=(0,0,0)
pixelsize=8 exportImages=True
exportImageFolder="imageexport/"
pixelsize=32
if exportImages:
pixelsize=1
color_checkerboardA=(0,0,0)
color_checkerboardB=(0,0,0)
color_bg=(0,0,0)
color_text=(255,255,255)
#fontname="font_normal" #fontname="font_normal"
#font = pygame.font.Font("Minecraftia-Regular.ttf", fontsize*pixelsize); #font = pygame.font.Font("Minecraftia-Regular.ttf", fontsize*pixelsize);
#fontsize=8 #fontsize=8
#pixelsW=6 #pixelsW=6
#pixelsH=8 #pixelsH=8KeyboardInterrupt
#offset=(0,0) #offset=(0,0)
fontname="font_large" #fontname="font_large"
fontsize=16 #fontsize=16
pixelsW=9 #pixelsW=9
pixelsH=8*2 #pixelsH=8*2
offset=(0,8) #offset=(0,1)
font = pygame.font.Font("Sweet16mono.ttf", fontsize*pixelsize); # https://github.com/kmar/Sweet16Font #font = pygame.font.Font("Sweet16mono.ttf", fontsize*pixelsize); # https://github.com/kmar/Sweet16Font
fontname="font_small"
fontsize=10
pixelsW=3
pixelsH=8
offset=(0,2)
font = pygame.font.Font("pzim3x5.ttf", fontsize*pixelsize); # https://www.fonts4free.net/pixelzim-3x5-font.html
@ -33,6 +57,8 @@ ascii = asciioffset
file = open("output.txt", "w") # write mode file = open("output.txt", "w") # write mode
@ -42,7 +68,7 @@ file.write("const uint8_t "+fontname+"_offset="+str(asciioffset)+";\n");
#file.write("uint8_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"];\n") #file.write("uint8_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"];\n")
file.write("const uint"+str(pixelsH)+"_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"]= {\n") file.write("const uint"+str(pixelsH)+"_t "+fontname+"["+str(asciiend-asciioffset+1)+"]["+str(pixelsW)+"]= {\n")
screen.fill((255, 255, 255)) screen.fill(color_bg)
screencleared=False screencleared=False
@ -56,17 +82,17 @@ while not done:
if not screencleared or not persistance: if not screencleared or not persistance:
screencleared=True screencleared=True
screen.fill((255, 255, 255)) screen.fill(color_bg)
for y in range(pixelsH): for y in range(pixelsH):
for x in range(pixelsW): for x in range(pixelsW):
color=(250,250,250) color=color_checkerboardA
if (x+y)%2==0: if (x+y)%2==0:
color=(200,200,200) color=color_checkerboardA
pygame.draw.rect(screen, color, pygame.Rect(pixelsize*x, pixelsize*y, pixelsize, pixelsize)) pygame.draw.rect(screen, color, pygame.Rect(pixelsize*x, pixelsize*y, pixelsize, pixelsize))
text = font.render(chr(ascii), True, (0, 0, 0)) text = font.render(chr(ascii), True, color_text)
screen.blit(text,(0+offset[0],-pixelsize*2+offset[1])) screen.blit(text,(0+offset[0]*pixelsize,-pixelsize*2+offset[1]*pixelsize))
print("ascii="+str(ascii)+" char="+chr(ascii)) print("ascii="+str(ascii)+" char="+chr(ascii))
''' '''
@ -85,7 +111,7 @@ while not done:
string8="" string8=""
for y in range(pixelsH): for y in range(pixelsH):
readcolor = screen.get_at(((int)(pixelsize*x+pixelsize/2),(int)(pixelsize*y+pixelsize/2))) readcolor = screen.get_at(((int)(pixelsize*x+pixelsize/2),(int)(pixelsize*y+pixelsize/2)))
if (readcolor==(0,0,0)): if (readcolor==color_text):
int8number+=pow(2,y) int8number+=pow(2,y)
string8+='1' string8+='1'
else: else:
@ -105,12 +131,19 @@ while not done:
pygame.display.flip()
if exportImages:
exportrect=pygame.Rect(0,0,pixelsW,pixelsH)
sub = screen.subsurface(exportrect)
pygame.image.save(sub, exportImageFolder+str(ascii)+".png")
clock.tick(fps)
ascii+=1 ascii+=1
if (ascii>asciiend): if (ascii>asciiend):
done=True done=True
pygame.display.flip()
clock.tick(fps)
file.write("};") file.write("};")
file.close() file.close()

BIN
imagegenerator/chicken.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

BIN
imagegenerator/egg.xcf Normal file

Binary file not shown.

BIN
imagegenerator/egg_c.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 669 B

78
imagegenerator/egg_c.txt Normal file
View File

@ -0,0 +1,78 @@
msg.payload="\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000111111000\
0000011000000100\
0001100000000010\
0010000111000001\
0100011000000001\
0100100000000001\
0100000000000001\
0100000000000001\
0100000000000001\
0010000000000001\
0001100000000010\
0000011000000100\
0000000111111000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
";
return msg;

BIN
imagegenerator/egg_l.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 B

78
imagegenerator/egg_l.txt Normal file
View File

@ -0,0 +1,78 @@
msg.payload="\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000111111000\
0000011000000100\
0001100000000010\
0010000111000001\
0100011000000001\
0100100000000001\
0100000000000001\
0100000000000001\
0100000000000001\
0010000000000001\
0001100000000001\
0000011000000110\
0000000111111000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
";
return msg;

BIN
imagegenerator/egg_r.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 667 B

78
imagegenerator/egg_r.txt Normal file
View File

@ -0,0 +1,78 @@
msg.payload="\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000111111000\
0000011000000110\
0001100000000001\
0010000111000001\
0100011000000001\
0100100000000001\
0100000000000001\
0100000000000001\
0100000000000001\
0010000000000001\
0001100000000010\
0000011000000100\
0000000111111000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
0000000000000000\
";
return msg;

View File

@ -5,6 +5,6 @@ while [ $i -ne 10 ]
do do
echo "$i" echo "$i"
python ../generate.py retrostyle_isolated/$i.png -f nodered -o $i.txt python ../generate.py pzim3x5/$i.png -f nodered -o $i.txt
i=$(($i+1)) i=$(($i+1))
done done