Python script to generate image with png.py
#!/usr/bin/env python
data = '''\
+++++
+++:+++++
+++::::+++
++:::@@@+++
+@@::+@.@++
+@::::::+++
+:+:::::++++
+::@+::++++
+++::::++++++
+++++::::..++
++.::::....++
......::..
:....::.
:...::++
+:::::++++
+++::.++++++
+:.....:++++
..:++:....:++
..:@@+++@@:...
.:@@++@@@++@@@:.'''
maps = {' ':0,'@':0,'+':1,':':2,'.':3}
datass = [[maps[char] for char in (row + ' ')[:16][::-1]] for row in data.split('\n')]
height = len(datass)
width = len(datass[0]) * 2
pixels = [0] * (width * height)
import png, copy
integralss = copy.deepcopy(datass)
def draw_pixel(pixels, width, x, y, luma): pixels[width * y + x] = luma
def tabbify(cellss, separator='|'):
cellpadss = [list(rows) + [''] * (len(max(cellss, key=len)) - len(rows)) for rows in cellss]
fmts = ['%%%ds' % (max([len(str(cell)) for cell in cols])) for cols in zip(*cellpadss)]
return '\n'.join([separator.join(fmts) % tuple(rows) for rows in cellpadss])
for (y, datas) in enumerate(datass):
for (x, data ) in enumerate(datas ):
integralss[y][x] = (data
+ (0 if y < 1 else integralss[y - 1][x ])
+ (0 if x < 1 else integralss[y ][x - 1])
- (0 if y < 1 or x < 1 else integralss[y - 1][x - 1]))
integral_max = max(max(integralss))
print(tabbify(integralss))
print(integral_max)
for (y, datas) in enumerate(datass):
for (x, data ) in enumerate(datas ):
draw_pixel(pixels, width, x , y, data * 85)
draw_pixel(pixels, width, x + width // 2, y, 255 * integralss[y][x] // integral_max)
png.Writer(width=width, height=height, alpha=False, greyscale=True).write_array(
open('%s.png' % (__file__[:__file__.rfind('.')]), 'wb'), pixels)