- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path25.py
More file actions
Latest commit
113 lines (95 loc) · 2.83 KB
/
Copy path25.py
File metadata and controls
113 lines (95 loc) · 2.83 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
importrequests
importwave
fromPILimportImage
fromPILimportImageDraw
defmain():
seed="http://www.pythonchallenge.com/pc/hex/"
file_path="lake/"
auth= ("butter", "fly")
# first_step(seed, file_path, auth)
# bss = second_step()
# all_pixel = third_step(bss)
# fourth_step(all_pixel)
fifth_step()
deffirst_step(seed, file_path, auth):
foriinrange(1, 26):
url=seed+"lake"+str(i) +".wav"
file_name=file_path+str(i) +".wav"
download_a_file(url, file_name, auth)
defdownload_a_file(url, file_name, auth):
res=requests.get(url, auth=auth)
bs=res.content
file=open(file_name, "wb")
file.write(bs)
print("Download {}".format(file_name))
defsecond_step():
bsAry= []
foriinrange(1, 26):
lake=wave.open("lake/{}.wav".format(i), "rb")
bs=lake.readframes(lake.getnframes())
print(bs)
bsAry.append(bs)
lake.close()
returnbsAry
defthird_step2(bss):
result_file=wave.open("lake/result.wav", "wb")
src_file=wave.open("lake/1.wav", "rb")
nframes=src_file.getnframes()
result_file.setnchannels(src_file.getnchannels())
result_file.setsampwidth(src_file.getsampwidth())
result_file.setframerate(src_file.getframerate())
result_file.setnframes(nframes*25)
foriinrange(len(bss)):
bs=bss[i]
result_file.writeframesraw(bs)
src_file.close()
result_file.close()
print("Done")
defthird_step(bss):
all_pixel= []
foriinrange(len(bss)):
bs=bss[i]
bs_len=len(bs)
j=0
pixels= []
whileTrue:
ifj>=bs_len:
break;
x=bs[j]
j+=1
ifj>=bs_len:
break;
y=bs[j]
j+=1
ifj>=bs_len:
break;
z=bs[j]
j+=1
pixel= (x, y, z)
pixels.append(pixel)
all_pixel.append(pixels)
print(all_pixel)
returnall_pixel
deffourth_step(all_pixel):
foriinrange(len(all_pixel)):
im=Image.new("RGB", (60, 60))
drawer=ImageDraw.Draw(im)
pixels=all_pixel[i]
count=0
forxinrange(60):
foryinrange(60):
print("drawing i={}, count={}, x={}, y={}".format(i, count, x, y))
drawer.point((x, y), pixels[count])
count+=1
im.save("lake/pic/{}.png".format(i))
deffifth_step():
im=Image.new("RGB", (300, 300))
foriinrange(25):
x= (i//5) *60
y= (i%5) *60
im_tmp=Image.open("lake/pic/{}.png".format(i))
im.paste(im_tmp, (x, y))
print("i={}, x={}, y={}".format(i, x, y))
im.save("lake/pic/result.png")
if__name__=="__main__":
main()