codeblock

2016年4月1日 星期五

Python Challenge level 16

http://www.pythonchallenge.com/pc/return/mozart.html (login: huge/file)

- Only a meaning less image. A title refers that "let me get this straight", so maybe I need to find something NOT straight ... this picture?
- Observe that there are many pink segments in this picture.
-  Every row has a small pink segment, what we should do is shift pixels of a row to make the pink segment at the start position in each row.


from PIL import Image
mozart = Image.open("mozart.gif")
pixels = mozart.load()
width, height = mozart.size

result = Image.new(mode=mozart.mode, size=mozart.size, color=0)
result_pixels = result.load()
for i in range(height):
 start_index = 0
 for j in range(width):
  if pixels[j, i] == 195:
   start_index = j
   break
 for j in range(width):
  result_pixels[j, i] = pixels[start_index, i]
  start_index = 0 if (start_index+1 == width) else start_index + 1

result.save("result.gif")
- The result picture is like:


















- The answer is "romance"

沒有留言:

張貼留言