Skip to content

Commit 652389c

Browse files
solved 25
1 parent 746c000 commit 652389c

30 files changed

+71
-7
lines changed

Diff for: 25.py

+62-6
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import requests
22
import wave
3+
from PIL import Image
4+
from PIL import ImageDraw
35

46

57
def main():
68
seed = "http://www.pythonchallenge.com/pc/hex/"
79
file_path = "lake/"
810
auth = ("butter", "fly")
911
# first_step(seed, file_path, auth)
10-
bs = second_step()
11-
third_step(bs)
12+
# bss = second_step()
13+
# all_pixel = third_step(bss)
14+
# fourth_step(all_pixel)
15+
fifth_step()
1216

1317

1418
def first_step(seed, file_path, auth):
@@ -37,21 +41,73 @@ def second_step():
3741
return bsAry
3842

3943

40-
def third_step(bs):
44+
def third_step2(bss):
4145
result_file = wave.open("lake/result.wav", "wb")
4246
src_file = wave.open("lake/1.wav", "rb")
4347
nframes = src_file.getnframes()
4448
result_file.setnchannels(src_file.getnchannels())
4549
result_file.setsampwidth(src_file.getsampwidth())
4650
result_file.setframerate(src_file.getframerate())
4751
result_file.setnframes(nframes * 25)
48-
for i in range(len(bs)):
49-
b = bs[i]
50-
result_file.writeframesraw(b)
52+
for i in range(len(bss)):
53+
bs = bss[i]
54+
result_file.writeframesraw(bs)
5155
src_file.close()
5256
result_file.close()
5357
print("Done")
5458

5559

60+
def third_step(bss):
61+
all_pixel = []
62+
for i in range(len(bss)):
63+
bs = bss[i]
64+
bs_len = len(bs)
65+
j = 0
66+
pixels = []
67+
while True:
68+
if j >= bs_len:
69+
break;
70+
x = bs[j]
71+
j += 1
72+
if j >= bs_len:
73+
break;
74+
y = bs[j]
75+
j += 1
76+
if j >= bs_len:
77+
break;
78+
z = bs[j]
79+
j += 1
80+
pixel = (x, y, z)
81+
pixels.append(pixel)
82+
all_pixel.append(pixels)
83+
print(all_pixel)
84+
return all_pixel
85+
86+
87+
def fourth_step(all_pixel):
88+
for i in range(len(all_pixel)):
89+
im = Image.new("RGB", (60, 60))
90+
drawer = ImageDraw.Draw(im)
91+
pixels = all_pixel[i]
92+
count = 0
93+
for x in range(60):
94+
for y in range(60):
95+
print("drawing i={}, count={}, x={}, y={}".format(i, count, x, y))
96+
drawer.point((x, y), pixels[count])
97+
count += 1
98+
im.save("lake/pic/{}.png".format(i))
99+
100+
101+
def fifth_step():
102+
im = Image.new("RGB", (300, 300))
103+
for i in range(25):
104+
x = (i // 5) * 60
105+
y = (i % 5) * 60
106+
im_tmp = Image.open("lake/pic/{}.png".format(i))
107+
im.paste(im_tmp, (x, y))
108+
print("i={}, x={}, y={}".format(i, x, y))
109+
im.save("lake/pic/result.png")
110+
111+
56112
if __name__ == "__main__":
57113
main()

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# pythonchallenge
22
Solve Problems in http://www.pythonchallenge.com
33

4+
5+
#### 25
6+
result: http://www.pythonchallenge.com/pc/hex/decent.html
7+
8+
- lake1.html means there is a file named with lake2
9+
- **imagine how they sound**
10+
411
#### 24
512
result: http://www.pythonchallenge.com/pc/hex/lake.html
613
```python

Diff for: lake/pic/0.png

3.8 KB
Loading

Diff for: lake/pic/1.png

3.15 KB
Loading

Diff for: lake/pic/10.png

7.59 KB
Loading

Diff for: lake/pic/11.png

7.93 KB
Loading

Diff for: lake/pic/12.png

7.76 KB
Loading

Diff for: lake/pic/13.png

7.5 KB
Loading

Diff for: lake/pic/14.png

7.47 KB
Loading

Diff for: lake/pic/15.png

7.38 KB
Loading

Diff for: lake/pic/16.png

7.53 KB
Loading

Diff for: lake/pic/17.png

7.54 KB
Loading

Diff for: lake/pic/18.png

7.11 KB
Loading

Diff for: lake/pic/19.png

6.51 KB
Loading

Diff for: lake/pic/2.png

2.83 KB
Loading

Diff for: lake/pic/20.png

5.35 KB
Loading

Diff for: lake/pic/21.png

6.48 KB
Loading

Diff for: lake/pic/22.png

6.7 KB
Loading

Diff for: lake/pic/23.png

6.14 KB
Loading

Diff for: lake/pic/24.png

5.71 KB
Loading

Diff for: lake/pic/3.png

2.26 KB
Loading

Diff for: lake/pic/4.png

2.34 KB
Loading

Diff for: lake/pic/5.png

7.17 KB
Loading

Diff for: lake/pic/6.png

6.22 KB
Loading

Diff for: lake/pic/7.png

4.34 KB
Loading

Diff for: lake/pic/8.png

4.23 KB
Loading

Diff for: lake/pic/9.png

4.34 KB
Loading

Diff for: lake/pic/result.png

179 KB
Loading

Diff for: lake/result.wav

-264 KB
Binary file not shown.

Diff for: read-bin-file.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ def read_bin_file(file_path):
1717
# read_bin_file("lake/2.wav")
1818
# read_bin_file("indian/indian.wav")
1919
# read_bin_file("indian/result.wav")
20-
read_bin_file("maze/maze/mybroken.gif")
20+
# read_bin_file("maze/maze/mybroken.gif")
21+
read_bin_file("lake/lake1.jpg")

0 commit comments

Comments
 (0)