摘要
|
Display like so:
|
Integral image (right half) of a 2-bit greyscale pixel art (left half), normalised and magnified for visibility
|
|
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)
许可协议
我,本作品著作权人,特此采用以下许可协议发表本作品:
- 您可以自由地:
- 共享 – 复制、发行并传播本作品
- 修改 – 改编作品
- 惟须遵守下列条件:
- 署名 – 您必须对作品进行署名,提供授权条款的链接,并说明是否对原始内容进行了更改。您可以用任何合理的方式来署名,但不得以任何方式表明许可人认可您或您的使用。
- 相同方式共享 – 如果您再混合、转换或者基于本作品进行创作,您必须以与原先许可协议相同或相兼容的许可协议分发您贡献的作品。
https://creativecommons.org/licenses/by-sa/4.0CC BY-SA 4.0 Creative Commons Attribution-Share Alike 4.0 truetrue
|
已授权您依据自由软件基金会发行的无固定段落及封面封底文字(Invariant Sections, Front-Cover Texts, and Back-Cover Texts)的GNU自由文件许可协议1.2版或任意后续版本的条款,复制、传播和/或修改本文件。该协议的副本请见“GNU Free Documentation License”。http://www.gnu.org/copyleft/fdl.htmlGFDLGNU Free Documentation Licensetruetrue
|
添加一行文字以描述该文件所表现的内容