Chinaunix首页 | 论坛 | 博客
  • 博客访问: 111282
  • 博文数量: 49
  • 博客积分: 2612
  • 博客等级: 少校
  • 技术积分: 431
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-01 14:31
个人简介

来来去去

文章分类

全部博文(49)

文章存档

2015年(1)

2012年(4)

2011年(1)

2010年(42)

2009年(1)

我的朋友

分类: Python/Ruby

2010-02-22 16:13:10



提示:
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)



阅读(416) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~