[Level 14]
Title: walk around
這次有兩張圖片,第二張實(shí)際上是100001像素的圖片。源碼中有提示:remember: 100100 = (100+99+99+98) + (...。實(shí)在想不出來(lái),搜索了知道是將第二張圖片照第一張圖螺旋地重新排列,提示信息括號(hào)中指的是從最外圈開(kāi)始排列的每一圈步數(shù)。
from PIL import Image
img = Image.open('wire.png')
newImg = Image.new(img.mode,(100,100))
y, t, count =0, 0, 0
while t<10000:
for x in range(0+count,100-count):
newImg.putpixel((x,y),img.getpixel((t,0)))
t = t + 1
for y in range(0+count,99-count):
newImg.putpixel((x,y),img.getpixel((t,0)))
t = t + 1
for x in range(99-count,0+count,-1):
newImg.putpixel((x,y),img.getpixel((t,0)))
t = t + 1
for y in range(98-count,0+count,-1):
newImg.putpixel((x,y),img.getpixel((t,0)))
t = t + 1
count=1+count
newImg.show()
得到一幅的圖片,修改為cat.html,顯示and its name is uzi. you'll hear from him later.,再次修改url,[Level 15]
小結(jié)
錯(cuò)誤的排列可能會(huì)得到bit,bit.html提示you took the wrong curve.。使用getdata()
和putdata()
方法也可以達(dá)到同樣效果。
Python Challenge Wiki
可以定義方向(或步驟),觸發(fā)某個(gè)條件執(zhí)行類(lèi)似轉(zhuǎn)向的操作,或者旋轉(zhuǎn),然后繼續(xù)排列。
from PIL import Image
src = Image.open('wire.png')
dst = Image.new(src.mode, (100, 100))
x, y, idx = -1, 0, 0 # back a step
steps = [1,0, 0,1, -1,0, 0,-1]
while idx < 10000:
nx, ny = x + steps[0], y + steps[1]
if 0 <= nx < 100 and 0 <= ny < 100 \
and dst.getpixel((nx, ny)) == (0, 0, 0):
x, y = nx, ny
dst.putpixel((x, y), src.getpixel((idx, 0)))
idx += 1
else:
steps = steps[2:] + steps[:2] # turn
dst.show()