Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitea198c4

Browse files
try 24
1 parentbe8103a commitea198c4

File tree

8 files changed

+435
-123
lines changed

8 files changed

+435
-123
lines changed

‎24-bak.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
fromPILimportImage
2+
importlogging
3+
4+
5+
defmain():
6+
logging.basicConfig(filename="maze/24.log",filemode="w",level=logging.DEBUG,
7+
format='%(asctime)s=>%(message)s')
8+
file_path="maze/maze.png"
9+
im=first_step(file_path)
10+
im_size=im.size
11+
width=im_size[0]# 641
12+
height=im_size[1]# 641
13+
# second_step(im, height)
14+
start= (639,0)
15+
third_step(im,start,width,height)
16+
17+
18+
deffirst_step(file_path):
19+
im=Image.open(file_path)
20+
returnim
21+
22+
23+
defsecond_step(im,height):
24+
y=0
25+
forxinrange(height):
26+
pixel=im.getpixel((x,y))
27+
ifpixel!= (255,255,255,255)andpixel!= (127,127,127,255):
28+
print("x={}, y={}, pixel={}".format(x,y,pixel))
29+
30+
31+
defthird_step(im,start,width,height):
32+
x=start[0]
33+
y=start[1]
34+
point_ary= [(x,y)]
35+
way="0"
36+
ways= {way:point_ary}
37+
go_to_end(im,x,y,point_ary,way,ways)
38+
39+
40+
defrouter(im,points,way,ways):
41+
logging.info("router start: ways={}".format(ways))
42+
tmp_way_value=ways[way]
43+
logging.info("delting way={}".format(way))
44+
delways[way]
45+
foriinrange(len(points)):
46+
point=points[i]
47+
next_way=str(int(way)+1+i)
48+
logging.info("next_way={}".format(next_way))
49+
ways[next_way]=tmp_way_value
50+
x=point[0]
51+
y=point[1]
52+
next_point_ary=ways[next_way]
53+
next_point_ary.append((x,y))
54+
tmp_ways=ways
55+
tmp_ways_keys=tmp_ways.keys()
56+
forkeyintmp_ways_keys:
57+
now_points=tmp_ways[key]
58+
now_points_tail=now_points[-1]
59+
x=now_points_tail[0]
60+
y=now_points_tail[1]
61+
go_to_end(im,x,y,now_points,key,ways)
62+
logging.info("router end: ways={}".format(ways))
63+
64+
65+
defgo_to_end(im,x,y,point_ary,way,ways):
66+
logging.info("go_to_end start: ways={}".format(ways))
67+
points=find_next_point(im,x,y,point_ary)
68+
ifpointsisNone:
69+
logging.info("delting way={}".format(way))
70+
delways[way]
71+
else:
72+
len_points=len(points)
73+
iflen_points==1:
74+
x=points[0][0]
75+
y=points[0][1]
76+
point_ary.append((x,y))
77+
go_to_end(im,x,y,point_ary,way,ways)
78+
else:
79+
router(im,points,way,ways)
80+
81+
82+
deffind_next_point(im,x,y,ok_points):
83+
logging.info("now is ({}, {}) finding next_point".format(x,y))
84+
right_x=x+1
85+
left_x=x-1
86+
up_y=y-1
87+
down_y=y+1
88+
ifright_x>640:
89+
right_x_pixel=None
90+
else:
91+
right_x_pixel=im.getpixel((right_x,y))
92+
ifleft_x<0:
93+
left_x_pixel=None
94+
else:
95+
left_x_pixel=im.getpixel((left_x,y))
96+
ifup_y<0:
97+
up_y_pixel=None
98+
else:
99+
up_y_pixel=im.getpixel((x,up_y))
100+
ifdown_y>640:
101+
down_y_pixel=None
102+
else:
103+
down_y_pixel=im.getpixel((x,down_y))
104+
points= []
105+
right_point=right_x,y
106+
left_point=left_x,y
107+
up_point=x,up_y
108+
down_point=x,down_y
109+
next_director= {}
110+
ifright_x_pixelisnotNoneandright_x_pixel!= (255,255,255,255):
111+
# logging.info("right_x={}, y={}, right_x_pixel={}".format(right_x, y, right_x_pixel))
112+
points.append(right_point)
113+
ifleft_x_pixelisnotNoneandleft_x_pixel!= (255,255,255,255):
114+
# logging.info("left_x={}, y={}, left_x_pixel={}".format(left_x, y, left_x_pixel))
115+
points.append(left_point)
116+
ifup_y_pixelisnotNoneandup_y_pixel!= (255,255,255,255):
117+
# logging.info("x={}, up_y={}, up_y_pixel={}".format(x, up_y, up_y_pixel))
118+
points.append(up_point)
119+
ifdown_y_pixelisnotNoneanddown_y_pixel!= (255,255,255,255):
120+
# logging.info("x={}, down_y={}, down_y_pixel={}".format(x, down_y, down_y_pixel))
121+
points.append(down_point)
122+
forpointinpoints:
123+
now_index=ok_points.index((x,y))
124+
before=ok_points[now_index-1]
125+
ifbefore==point:
126+
logging.info("removing {}".format(point))
127+
points.remove(point)
128+
iflen(points)<1:
129+
logging.info("return None")
130+
returnNone
131+
logging.info("return points={}".format(points))
132+
points2= [points[0]]
133+
returnpoints2
134+
135+
136+
if__name__=="__main__":
137+
main()

‎24-test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fromqueueimportQueue
2+
3+
defmain():
4+
first_step()
5+
6+
7+
deffirst_step():
8+
q=Queue()
9+
q.put('a')
10+
q.put('b')
11+
print(q.get())
12+
13+
14+
if__name__=="__main__":
15+
main()

‎24-test2.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
fromthreadingimportThread
2+
importqueue
3+
4+
num_worker_threads=10
5+
queue=queue.Queue(maxsize=0)
6+
7+
8+
defprocess(item):
9+
print("doing work for %(item)s"%locals())
10+
11+
12+
defworker():
13+
whileTrue:
14+
item=queue.get()
15+
process(item)
16+
queue.task_done()
17+
18+
19+
foriinrange(num_worker_threads):
20+
thread=Thread(target=worker)
21+
thread.daemon=True
22+
thread.start()
23+
24+
foriteminrange(10):
25+
queue.put(item)
26+
27+
queue.join()
28+
29+
print("finished")

‎24-test3.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
importconcurrent.futures
2+
importurllib.request
3+
4+
URLS= ['http://www.foxnews.com/',
5+
'http://www.cnn.com/',
6+
'http://europe.wsj.com/',
7+
'http://www.bbc.co.uk/',
8+
'http://some-made-up-domain.com/']
9+
10+
# Retrieve a single page and report the URL and contents
11+
defload_url(url,timeout):
12+
withurllib.request.urlopen(url,timeout=timeout)asconn:
13+
returnconn.read()
14+
15+
# We can use a with statement to ensure threads are cleaned up promptly
16+
withconcurrent.futures.ThreadPoolExecutor(max_workers=5)asexecutor:
17+
# Start the load operations and mark each future with its URL
18+
future_to_url= {executor.submit(load_url,url,60):urlforurlinURLS}
19+
forfutureinconcurrent.futures.as_completed(future_to_url):
20+
url=future_to_url[future]
21+
try:
22+
data=future.result()
23+
exceptExceptionasexc:
24+
print('%r generated an exception: %s'% (url,exc))
25+
else:
26+
print('%r page is %d bytes'% (url,len(data)))

‎24-test4.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
fromconcurrentimportfutures
2+
3+
4+
deffoo(x,y):
5+
print("{}-{}={}".format(y,x,y-x ))
6+
returny-x
7+
8+
9+
defmain():
10+
withfutures.ProcessPoolExecutor()aspool:
11+
pool.map(foo, [1,2,3], [4,7,1000])
12+
13+
14+
if__name__=='__main__':
15+
main()

‎24-test5.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,13 @@ def remove_dic(dic, key):
2323

2424
defstart_operation(dic,pool):
2525
pool.submit(insert_dic,dic,"hello","world")
26+
pool.submit(remove_dic,dic,"hello")
27+
pool.submit(insert_dic,dic,"liu","bei")
28+
pool.submit(insert_dic,dic,"hi","happy")
2629

2730

2831
defmain():
29-
pool=ThreadPoolExecutor(max_workers=3)
32+
pool=ThreadPoolExecutor(max_workers=10000)
3033
# req(pool)
3134
dic= {}
3235
start_operation(dic,pool)

‎24.py

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,134 +1,16 @@
11
fromPILimportImage
2-
importlogging
32

43

54
defmain():
6-
logging.basicConfig(filename="maze/24.log",filemode="w",level=logging.DEBUG,
7-
format='%(asctime)s=>%(message)s')
85
file_path="maze/maze.png"
9-
im=first_step(file_path)
10-
im_size=im.size
11-
width=im_size[0]# 641
12-
height=im_size[1]# 641
13-
# second_step(im, height)
14-
start= (639,0)
15-
third_step(im,start,width,height)
6+
first_step(file_path)
167

178

189
deffirst_step(file_path):
1910
im=Image.open(file_path)
20-
returnim
21-
22-
23-
defsecond_step(im,height):
24-
y=0
25-
forxinrange(height):
26-
pixel=im.getpixel((x,y))
27-
ifpixel!= (255,255,255,255)andpixel!= (127,127,127,255):
28-
print("x={}, y={}, pixel={}".format(x,y,pixel))
29-
30-
31-
defthird_step(im,start,width,height):
32-
x=start[0]
33-
y=start[1]
34-
point_ary= [(x,y)]
35-
way="0"
36-
ways= {way:point_ary}
37-
go_to_end(im,x,y,point_ary,way,ways)
38-
39-
40-
defrouter(im,points,way,ways):
41-
logging.info("router start: ways={}".format(ways))
42-
tmp_way_value=ways[way]
43-
logging.info("delting way={}".format(way))
44-
delways[way]
45-
foriinrange(len(points)):
46-
point=points[i]
47-
next_way=str(int(way)+1+i)
48-
logging.info("next_way={}".format(next_way))
49-
ways[next_way]=tmp_way_value
50-
x=point[0]
51-
y=point[1]
52-
next_point_ary=ways[next_way]
53-
next_point_ary.append((x,y))
54-
ways_keys=ways.keys()
55-
forkeyinways_keys:
56-
now_points=ways[key]
57-
now_points_tail=now_points[-1]
58-
x=now_points_tail[0]
59-
y=now_points_tail[1]
60-
go_to_end(im,x,y,now_points,key,ways)
61-
logging.info("router end: ways={}".format(ways))
62-
63-
64-
defgo_to_end(im,x,y,point_ary,way,ways):
65-
logging.info("go_to_end start: ways={}".format(ways))
66-
points=find_next_point(im,x,y,point_ary)
67-
ifpointsisNone:
68-
logging.info("delting way={}".format(way))
69-
delways[way]
70-
else:
71-
len_points=len(points)
72-
iflen_points==1:
73-
x=points[0][0]
74-
y=points[0][1]
75-
point_ary.append((x,y))
76-
go_to_end(im,x,y,point_ary,way,ways)
77-
else:
78-
router(im,points,way,ways)
79-
80-
81-
deffind_next_point(im,x,y,ok_points):
82-
logging.info("now is ({}, {}) finding next_point".format(x,y))
83-
right_x=x+1
84-
left_x=x-1
85-
up_y=y-1
86-
down_y=y+1
87-
ifright_x>640:
88-
right_x_pixel=None
89-
else:
90-
right_x_pixel=im.getpixel((right_x,y))
91-
ifleft_x<0:
92-
left_x_pixel=None
93-
else:
94-
left_x_pixel=im.getpixel((left_x,y))
95-
ifup_y<0:
96-
up_y_pixel=None
97-
else:
98-
up_y_pixel=im.getpixel((x,up_y))
99-
ifdown_y>640:
100-
down_y_pixel=None
101-
else:
102-
down_y_pixel=im.getpixel((x,down_y))
103-
points= []
104-
right_point=right_x,y
105-
left_point=left_x,y
106-
up_point=x,up_y
107-
down_point=x,down_y
108-
next_director= {}
109-
ifright_x_pixelisnotNoneandright_x_pixel!= (255,255,255,255):
110-
logging.info("right_x={}, y={}, right_x_pixel={}".format(right_x,y,right_x_pixel))
111-
points.append(right_point)
112-
ifleft_x_pixelisnotNoneandleft_x_pixel!= (255,255,255,255):
113-
logging.info("left_x={}, y={}, left_x_pixel={}".format(left_x,y,left_x_pixel))
114-
points.append(left_point)
115-
ifup_y_pixelisnotNoneandup_y_pixel!= (255,255,255,255):
116-
logging.info("x={}, up_y={}, up_y_pixel={}".format(x,up_y,up_y_pixel))
117-
points.append(up_point)
118-
ifdown_y_pixelisnotNoneanddown_y_pixel!= (255,255,255,255):
119-
logging.info("x={}, down_y={}, down_y_pixel={}".format(x,down_y,down_y_pixel))
120-
points.append(down_point)
121-
forpointinpoints:
122-
now_index=ok_points.index((x,y))
123-
before=ok_points[now_index-1]
124-
ifbefore==point:
125-
logging.info("removing {}".format(point))
126-
points.remove(point)
127-
iflen(points)<1:
128-
logging.info("return None")
129-
returnNone
130-
logging.info("return points={}".format(points))
131-
returnpoints
11+
size=im.size
12+
width=size[0]
13+
height=size[1]
13214

13315

13416
if__name__=="__main__":

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp