import pygame pygame.init() screen = pygame.display.set_mode((640, 480)) clock = pygame.time.Clock() done = False persistance=False fps=10 pixelsize=8 #fontname="font_normal" #font = pygame.font.Font("Minecraftia-Regular.ttf", fontsize*pixelsize); #fontsize=8 #pixelsW=6 #pixelsH=8 #offset=(0,0) fontname="font_large" fontsize=16 pixelsW=9 pixelsH=8*2 offset=(0,8) font = pygame.font.Font("Sweet16mono.ttf", fontsize*pixelsize); # https://github.com/kmar/Sweet16Font asciioffset=33 asciiend=126 ascii = asciioffset file = open("output.txt", "w") # write mode file.write("const uint8_t "+fontname+"_width="+str(pixelsW)+";\n"); file.write("const uint8_t "+fontname+"_offset="+str(asciioffset)+";\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") screen.fill((255, 255, 255)) screencleared=False while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE: done = True if not screencleared or not persistance: screencleared=True screen.fill((255, 255, 255)) for y in range(pixelsH): for x in range(pixelsW): color=(250,250,250) if (x+y)%2==0: color=(200,200,200) pygame.draw.rect(screen, color, pygame.Rect(pixelsize*x, pixelsize*y, pixelsize, pixelsize)) text = font.render(chr(ascii), True, (0, 0, 0)) screen.blit(text,(0+offset[0],-pixelsize*2+offset[1])) print("ascii="+str(ascii)+" char="+chr(ascii)) ''' uint16_t font[COLUMNS]; font[ascii][column]=0b00000000; int a[2][3] = { {0, 2, 1} , /* row at index 0 */ {4, 3, 7} , /* row at index 1 */ }; ''' file.write("{") for x in range(pixelsW): int8number=0 string8="" for y in range(pixelsH): readcolor = screen.get_at(((int)(pixelsize*x+pixelsize/2),(int)(pixelsize*y+pixelsize/2))) if (readcolor==(0,0,0)): int8number+=pow(2,y) string8+='1' else: string8+='0' #file.write(fontname+"["+str(ascii-asciioffset)+"]["+str(x)+"]=0b"+string8+";\n") file.write(str(int8number)) if (xasciiend): done=True pygame.display.flip() clock.tick(fps) file.write("};") file.close()