Skip to content

Commit cd896a5

Browse files
14
1 parent 7b527b4 commit cd896a5

File tree

3 files changed

+48
-7
lines changed

3 files changed

+48
-7
lines changed

14.py

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,39 @@
1616
count = 0
1717
x = 0
1818
y = 0
19-
while y < result_y:
20-
while x < result_x:
21-
# print("count is {}, im.getpixel((count,0)) is{}".format(count,im.getpixel((count, 0))))
19+
len_x = result_x
20+
len_y = result_y
21+
while y < len_y:
22+
while x < len_x:
23+
# print("x={}, y={}, count={}".format(x, y, count))
2224
drawer.point((x, y), im.getpixel((count,0)))
2325
x += 1
2426
count += 1
27+
x -= 1
28+
len_x -= 1
2529
y += 1
26-
x = 0
30+
while y < len_y:
31+
# print("x={}, y={}, count={}".format(x, y, count))
32+
drawer.point((x, y), im.getpixel((count,0)))
33+
y += 1
34+
count += 1
35+
y -= 1
36+
len_y -= 1
37+
x -= 1
38+
while x >= result_x - len_x - 1:
39+
# print("x={}, y={}, count={}".format(x, y, count))
40+
drawer.point((x, y), im.getpixel((count,0)))
41+
x -= 1
42+
count += 1
43+
x += 1
44+
y -= 1
45+
while y >= result_y - len_y:
46+
# print("x={}, y={}, count={}, result_y={}, len_y={}".format(x, y, count, result_y, len_y))
47+
drawer.point((x, y), im.getpixel((count,0)))
48+
y -= 1
49+
count += 1
50+
y += 1
51+
x += 1
2752

28-
result.show()
53+
result.show()
54+
result.save("wire/cat.png")

README.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,23 @@
22
Solve Problems in http://www.pythonchallenge.com
33

44
#### 14
5-
result:
6-
5+
result: http://www.pythonchallenge.com/pc/return/uzi.html
6+
```
7+
from PIL import Image
8+
from PIL import ImageDraw
9+
```
10+
- the key of this problem is to use 100 * 100 = 100 + 99 + 99 + 98 + 98 + 97 + 97 + ...
11+
- the size of cat.png is 100 * 100
12+
- use ImageDraw.point()
13+
- result is "wire/cat.png"
14+
```
15+
while(
16+
left(0,0) -> right(99,0) 100
17+
up(99,1) -> down(99,99) 99
18+
right(99,98) -> left(99,0) 99
19+
down(98,0) -> up (1,0) 98
20+
)
21+
```
722

823
#### 13
924
result: http://www.pythonchallenge.com/pc/return/italy.html

wire/cat.png

14.5 KB
Loading

0 commit comments

Comments
 (0)