摘要
|
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
|
已授權您依據自由軟體基金會發行的無固定段落、封面文字和封底文字GNU自由文件授權條款1.2版或任意後續版本,對本檔進行複製、傳播和/或修改。該協議的副本列在GNU自由文件授權條款中。http://www.gnu.org/copyleft/fdl.htmlGFDLGNU Free Documentation Licensetruetrue
|