PrintLarge

printlarge.py

This is an example of how bitmap fonts work. It can also be used to display decimal values in a very large font on simple terminals.

Result

File:Printlarge.png

  1. !/usr/bin/env python
  2. encoding: utf-8

""" printlarge.py

A simple example of how bitmap fonts work.

Created by Martin Hepp on 2009-11-17 http://www.heppnetz.de

"""

  1. The following Python dictionary holds the graphical patterns for each digit and the comma.

font = {'0':(

       '****',
       '*  *',
       '*  *',
       '*  *',
       '*  *',
       '*  *',
       '****'),
   '1':(
       '  *  ',
       '  *  ',
       '  *  ',
       '  *  ',
       '  *  ',
       '  *  ',
       '  *  '),       
   '2':(
       '****',
       '   *',
       '   *',
       '****',
       '*   ',
       '*   ',
       '****'),
   '3':(
       '****',
       '   *',
       '   *',
       '****',
       '   *',
       '   *',
       '****'),
   '4':(
       '*  *',
       '*  *',
       '*  *',
       '****',
       '   *',
       '   *',
       '   *'),
   '5':(
       '****',
       '*   ',
       '*   ',
       '****',
       '   *',
       '   *',
       '****'),
   '6':(
       '*   ',
       '*   ',
       '*   ',
       '****',
       '*  *',
       '*  *',
       '****'),        
   '7':(
       '****',
       '   *',
       '   *',
       '   *',
       '   *',
       '   *',
       '   *'),
   '8':(
       '****',
       '*  *',
       '*  *',
       '****',
       '*  *',
       '*  *',
       '****'),
   '9':(
       '****',
       '*  *',
       '*  *',
       '****',
       '   *',
       '   *',
       '   *'),
   ',':(
       '    ',
       '    ',
       '    ',
       '    ',
       ' ** ',
       ' ** ',
       ' ** ')         
   }

  1. main program

text = "199,49" # define number to be displayed rows = ["","","","","","",""] # seven empty strings representing each line of the output

for char in text:

   pattern = font[char]
   for i in range(7):
       rows[i] += pattern[i] + " "

for line in rows:

   print line