#!/usr/bin/env python import os, sys, string, struct os.chdir(os.pardir) sys.path.insert(0, os.getcwd()) sys.path.insert(1, os.path.abspath(os.path.join(os.pardir, 'common'))) from images import sprmap import bonuses, images try: import psyco; psyco.full() except ImportError: pass def create_image(name,source,extralines=0,alt=''): if len(sys.argv) == 2 and sys.argv[1] == '-i': return print name, source src = open(source[0],'r') assert src.readline().strip() == 'P6' line = src.readline() while line[0] == '#': line = src.readline() size = string.split(line) w = string.atoi(size[0]) h = string.atoi(size[1]) c = src.readline().strip() data = src.read() src.close() img = os.popen("convert PPM:- doc/images/"+name+'.png','w') print >> img, 'P6' print >> img, source[1][2], source[1][3]+extralines print >> img, c cx = source[1][0]+source[1][2]//2 cy = source[1][1]+source[1][3]*6//7 for y in range(source[1][1],source[1][1]+source[1][3]): for x in range(source[1][0],source[1][0]+source[1][2]): rgb = data[y*3*w+3*x:y*3*w+3*x+3] if rgb == '\x01\x01\x01': d = (x-cx)*(x-cx)+(y-cy)*(y-cy)*6 if d > 255: d = 255 rgb = chr(d)*3 img.write(rgb) for y in range(y+1, y+1+extralines): for x in range(source[1][0],source[1][0]+source[1][2]): d = (x-cx)*(x-cx)+(y-cy)*(y-cy)*6 if d > 255: d = 255 rgb = chr(d)*3 img.write(rgb) img.close() return html_tag(name, alt) def html_tag(name, alt): url = 'images/%s.png' % (name,) f = open('doc/'+url, 'rb') alldata = f.read() f.close() url = 'data:image/png;base64,' + alldata.encode('base64').replace('\n','') return '' % (url, alt) def split_name(name): "Split a name into its words based on capitalisation." words = [] word = '' for c in name: if c.isupper() and word != '': words.append(word) word = c else: word += c words.append(word) return words dfile = open('doc/bonuses.html','w') print >> dfile, """
regular bonus | big bonus | |||
', print >> dfile, images, print >> dfile, ' | ', print >> dfile, ' | %s | ' % (bgcolor, doc), print >> dfile, '' % bgcolor, print >> dfile, ' | %s |