pythonchallenge闯关 第14题
14、Hint:(1)walk around
(2)一张面包圈图片
(3)一张条纹图片(10000*1)显示为(100*100)
(4)<!-- remember: 100*100 = (100+99+99+98) + (... -->
第三个Hint和第四个Hint联起来想,为什么要100*100的显示,为什么要像100*100 = (100+99+99+98)+(…这样分解
其实(100+99+99+98)是100*100像素图片的最外面那一圈的像素
将wire.png平铺成一张100*100的图片
Wrong:
如果是一行一行的累加
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import Image new_img = Image.new('RGB', (100, 100)) f = Image.open("wire.png") width = 99 x, y = 0, 0 for z in range(10000): new_img.putpixel((x, y), f.getpixel((z, 0))) if x < width: x += 1 else: x = 0 y += 1 new_img.save("wire1.png", "PNG")
会得出下面这个图形
进入http://www.pythonchallenge.com/pc/return/bit.html
显示you took the wrong curve.
Right:
按照面包圈的形状螺旋累加
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
import Image new_img = Image.new('RGB', (100, 100)) f = Image.open("wire.png") bottom, right = 99, 99 top, left = 0, 0 x1, y1 = 1, 0 x, y = 0, 0 for z in range(10000): print x, y new_img.putpixel((x, y), f.getpixel((z, 0))) if x == bottom and x1 == 1: x1 = 0 y1 = 1 left += 1 if y == right and y1 == 1: x1 = -1 y1 = 0 bottom -= 1 if x == top and x1 == -1: x1 = 0 y1 = -1 right -= 1 if y == left and y1 == -1: x1 = 1 y1 = 0 top += 1 x += x1 y += y1 new_img.save("wire2.png", "PNG")
如果图片相反改个方向叠加
url:http://www.pythonchallenge.com/pc/return/cat.html
猫的名字叫uzi
下一题: