[Level 31]
Title: Where am I?
圖片鏈接的地址需要用戶名和密碼。以圖片搜索,搜出了 hin ta & hin yai rock,還有 Koh Samui,然而都不是用戶名密碼崎场。
Where am I? island: country。所以是 kohsamui 和 thailand遂蛀。真正的 Level 31 出來(lái)了谭跨,標(biāo)題為 UFOs ?,還有新的圖片:
嗯,Mandelbrot set(曼德博集合)螃宙,分形圖蛮瞄。利用源碼給出的參數(shù)畫出新圖形與原圖形比較。怎么構(gòu)圖污呼?
圖片的每一個(gè)坐標(biāo)(x, y)
代表復(fù)數(shù)c
裕坊,令z = 0 + 0j
,重復(fù)計(jì)算z = z * z + c
燕酷,如果z
限制在一定范圍內(nèi)籍凝,點(diǎn)亮該點(diǎn),否則設(shè)為黑色苗缩。事實(shí)上設(shè)置計(jì)算次數(shù)為該點(diǎn)的像素值饵蒂。
設(shè)w
和h
為圖片的寬度和高度,則c
的實(shí)部為left + x * width / w
酱讶,虛部為top + y * height / h
from PIL import Image
img = Image.open("mandelbrot.gif")
w, h = img.size
left, top, width, height = 0.34, 0.57, 0.036, 0.027
iters = 128
result = []
for y in range(h - 1, -1, -1):
for x in range(0, w):
z = 0 + 0j
c = complex(left + x * width / w, top + y * height / h)
for i in range(iters):
z = z * z + c
if abs(z) > 2:
break
result.append(i)
用得到的數(shù)據(jù)構(gòu)圖退盯,新圖與原圖沒(méi)多大差別,有少許像素點(diǎn)差值為 16 或 -16泻肯。收集起來(lái)渊迁,共有 1679 個(gè)。
img2 = img.copy()
img2.putdata(result)
img2.show()
diff = [(a-b) for a, b in zip(list(img.getdata()), result) if a != b]
print(len(diff))
將收集的數(shù)據(jù)用于構(gòu)成另一張圖灶挟。
img3 = Image.new('L', (23, 73))
img3.putdata([i>0 and 255 or 0 for i in diff])
img3.show()
搜索圖片可得到 arecibo(Messaggio di Arecibo)琉朽,[Level 32]