pythonchallenge-16地址 : http://www.pythonchallenge.com/pc/return/mozart.html
使用python 3.x 对pythonchallenge-----16的解答过程

题目解析:网站标题是 let me get this straight  
图片中每行有一个红色的区域,把红色的区域右边的放到前面,红色区域左边的放到后面,然后对齐

解题过程:
 
#http://www.pythonchallenge.com/pc/return/mozart.html
from PIL import Image
path = u'./other/mozart.gif'
img = Image.open(path)
imgnew = Image.new("P",(640,480),255)

print(img.getbbox())
print(img)

for i in range(480):
    z = 0
    for j in range(2,638):
        if  img.getpixel((j,i)) == img.getpixel((j -2 ,i) )== img.getpixel((j + 2,i)) == 195:
            z = j

    box_before  = (0,i,z,i+1)
    box_after  = (z,i,640,i+1)
    region_before = img.crop(box_before)
    region_after = img.crop(box_after)
    imgnew.paste(region_after, (0,i))
    imgnew.paste(region_before, (640-z,i))

imgnew.show()

 答案:romance

使用python 3.x 对pythonchallenge-----16的解答过程

 



 


 
 

相关文章:

  • 2021-06-24
  • 2021-08-07
  • 2021-12-02
  • 2021-07-14
  • 2022-03-06
  • 2021-08-13
  • 2021-06-09
  • 2021-09-22
猜你喜欢
  • 2022-03-08
  • 2021-10-12
  • 2021-07-12
  • 2021-12-10
  • 2021-12-11
  • 2021-05-18
  • 2022-03-03
相关资源
相似解决方案