-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathitaly.py
More file actions
32 lines (27 loc) · 860 Bytes
/
italy.py
File metadata and controls
32 lines (27 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/python
# coding: utf-8
# http://www.pythonchallenge.com/pc/return/italy.html
import urllib
import Image
# downlaod file with password
# user: huge passwd: file
url="http://huge:file@www.pythonchallenge.com/pc/return/wire.png"
filename=url.split('/')[-1]
urllib.urlretrieve(url,filename)
# tips
# remember: 100*100 = (100+99+99+98) + ... + (3+2+2+1) +1
im = Image.open("wire.png")
new = Image.new(im.mode, [100, 100])
#四个方向向量
vect=[(1, 0), (0, 1), (-1, 0), (0, -1)]
x, y, p, double_steps=-1, 0, 0, 200
#开始把像素往新图上盘
while p < 10000:
for v in vect:
for s in xrange(double_steps // 2):
x, y = x + v[0], y + v[1]
new.putpixel((x, y), im.getpixel((p, 0)))
p = p + 1
double_steps = double_steps - 1
new.save('14.jpg')
# cat -> uzi