Python Challenge[14]

作者: Recgat | 来源:发表于2017-02-11 16:37 被阅读0次

[Level 14]



Title: walk around

这次有两张图片,第二张实际上是100001像素的图片。源码中有提示:remember: 100100 = (100+99+99+98) + (...。实在想不出来,搜索了知道是将第二张图片照第一张图螺旋地重新排列,提示信息括号中指的是从最外圈开始排列的每一圈步数。

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]

小结

错误的排列可能会得到bitbit.html提示you took the wrong curve.。使用getdata()putdata()方法也可以达到同样效果。

Python Challenge Wiki

可以定义方向(或步骤),触发某个条件执行类似转向的操作,或者旋转,然后继续排列。

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()

More

相关文章

  • Python Challenge[14]

    [Level 14] Title: walk around 这次有两张图片,第二张实际上是100001像素的图片。...

  • Python挑战:00~03关

    Python Challenge Python Challenge 00 网址: http://www.pytho...

  • Python挑战:04-05关

    Python Challenge Python Challenge 04 现在,我们来挑战第四关,从第三关的结果,...

  • python马丁challenge14.Mediants

    Let two distinct reduced positive fractions F1 = p1q1 and...

  • The Python Challenge(5)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面源码提示: 再点击页面图片显示: 可知是需要...

  • The Python Challenge(8)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 页面和源码中无任何提示,但图片中有一条很明显的灰度线...

  • The Python Challenge(9)

    问题链接 问题链接如下: 答案链接 答案链接如下: 登陆用户名密码为huge和file。 解题思路 阅读源码有如下...

  • The Python Challenge(2)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 将页面给定的字符串根据给定规则进行替换即可,规则如下...

  • The Python Challenge(3)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面提示: 阅读源码,有如下内容: 编写代码从中...

  • The Python Challenge(4)

    问题链接 问题链接如下: 答案链接 答案链接如下: 解题思路 根据页面提示: 并结合页面源码中的内容,有如下代码:...

网友评论

    本文标题:Python Challenge[14]

    本文链接:https://www.haomeiwen.com/subject/gmowittx.html