Chinaunix

标题: 9 Draw [打印本页]

作者: angelia_liu    时间: 2010-02-22 16:13
标题: 9 Draw

                http://www.pythonchallenge.com/pc/return/good.html
提示:
1 标题:connect the dots
2 图片上有很多黑点。
3 通过查看源码可以看到有一系列的数字,并且有提示信息 first+second=?。
由此我们可以猜出源码里的的那些数字代表的是坐标,我们要坐的就是把这些坐标代表的位置画出来。
以下是通过draw_point函数实现的,我把那些数据都放在了test.txt文件里面。
               
               
                import Image,ImageDraw
def connect_dots():
    im=Image.open('good2.jpg')
    #print im.mode
    src=open('E:\\python challenge\\first.txt','rb').read()
    list=re.findall('\d+',src)  #get all the numeric values -->return list
    list=tuple(map(int,list))  # convert str value in list to int then change the list to tuple type
    draw=ImageDraw.Draw(im)
    color=(115,115,255)
    draw.point(list,color)
    im.save('good2.jpg')
connect_dots()
运行之后得到的图像为一头牛。把牛的英文单词(cow or bull)输入URL中我们就可以进入下一头了。
上面的图片看起来不是太清楚,我们可以用draw_line来实现。就是把这些坐标用线连起来。首先先把first,second这两个里面的数据放到两个list里面。
               
                import Image,ImageDraw
def connect_dots(first,second):
    first=first
    second=second
    img=Image.new('RGB',(640,600))
    draw=ImageDraw.Draw(img)
    draw.line(first)
    draw.line(second)
    img.show()
   
connect_dots(first,second)


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u3/107101/showart_2183985.html




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2