#! /usr/bin/python
import sys
import string
import Image
import ImageDraw
font = [
        [
            ".OO.",
            "O..O",
            "OOOO",
            "O..O",
            "O..O"
        ],
        [
            "OOOO",
            "O...",
            "O...",
            "O...",
            "OOOO"
        ],
        [
            "OOOO",
            "O...",
            "OOO.",
            "O...",
            "OOOO"
        ],
        [
            "OOOO",
            "O...",
            "OOO.",
            "O...",
            "O..."
        ],
        [
            "OOOO",
            "O...",
            "O.OO",
            "O..O",
            "OOOO"
        ],
        [
            "O..O",
            "O..O",
            "OOOO",
            "O..O",
            "O..O"
        ],
        [
            ".OOO",
            "..O.",
            "..O.",
            "..O.",
            "OOO."
        ],
        [
            "O...",
            "O...",
            "O...",
            "O...",
            "OOOO"
        ],
        [
            "OOOO",
            "O..O",
            "O..O",
            "O..O",
            "OOOO"
        ],
        [
            "OOOO",
            "O..O",
            "OOOO",
            "O...",
            "O..."
        ],
        [
            "OOOO",
            "O...",
            "OOOO",
            "...O",
            "OOOO"
        ],
        [
            "O..O",
            "O..O",
            "O..O",
            "O..O",
            "OOOO"
       ] 
]
font_w = 4;
font_h = 5;
numChars = 12;
numLabels = 70;
M = 5; # num pixels per meta-pixel

label_w = (2 * font_w + 3 ) * M; # the +3 is for margins
label_h = (font_h + 2 ) * M; # the +2 is for margins

numSets = 4
numRows = 25
numColsPerSet = 3

total_w = label_w * numSets * numColsPerSet
total_h = numRows * label_h

# outputImage = Image.new("RGB", (100,100),(255,255,255))
outputImage = Image.new("RGB", (total_w,total_h),(255,255,255))
draw = ImageDraw.Draw(outputImage)

# draw.rectangle([10, 20, 30, 80 ], outline=(0,0,0))


def fillRect(x,y,w,h):
   x2 = x+w-1
   y2 = y+h-1
   draw.rectangle([x,y,x2,y2],fill=(0,0,0))

def drawRect(x,y,w,h):
   x2 = x+w-1
   y2 = y+h-1
   draw.rectangle([x,y,x2,y2],outline=(128,128,128))


# this does not take margins into account
def plotChar(x0,y0,index):
   for x in range(font_w):
      for y in range(font_h):
         if font[index][y][x]=='O':
            fillRect(x0+x*M, y0+y*M, M,M)


for set in range(numSets):
   for col in range(numColsPerSet):
      for row in range(numRows):
         i = col * numRows + row
         if i > 71:
            continue
         drawRect( (set*numColsPerSet + col)*label_w, row * label_h, label_w, label_h )
         i1 = (i / numChars) % numChars
         i2 = i % numChars
         plotChar( (set*numColsPerSet + col)*label_w + M, row * label_h + M, i1 )
         plotChar( (set*numColsPerSet + col)*label_w + (font_w + 2)*M, row*label_h + M, i2 )


# print 'hey there'

outputImage.save("output.png")

