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

Commitd960727

Browse files
try 24
1 parent1ce1445 commitd960727

File tree

2 files changed

+108
-45
lines changed

2 files changed

+108
-45
lines changed

‎24-1.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
fromPILimportImage,ImageDraw
2+
3+
4+
defmain():
5+
# ary = [(639, 0), (639, 1), (639, 2), (639, 3), (639, 4), (639, 5), (639, 6), (639, 7), (639, 8), (639, 9),
6+
# (639, 10), (639, 11), (638, 11), (637, 11), (636, 11), (635, 11), (635, 12), (635, 13), (635, 14), (635, 15),
7+
# (635, 16), (635, 17), (636, 17), (637, 17), (637, 16), (637, 15), (637, 14), (637, 13), (638, 13), (639, 13),
8+
# (639, 14), (639, 15), (639, 16), (639, 17), (639, 18), (639, 19), (639, 20), (639, 21), (639, 22), (639, 23),
9+
# (638, 23), (637, 23), (637, 22), (637, 21), (636, 21), (635, 21), (635, 20), (635, 19), (636, 19), (637, 19)]
10+
ary= [(639,0), (639,1), (639,2), (639,3), (639,4), (639,5), (639,6), (639,7), (639,8), (639,9),
11+
(639,10), (639,11), (638,11), (637,11), (636,11), (635,11), (635,12), (635,13), (635,14), (635,15),
12+
(635,16), (635,17), (636,17), (637,17), (637,16), (637,15), (637,14), (637,13), (638,13), (639,13),
13+
(639,14), (639,15), (639,16), (639,17), (639,18), (639,19), (639,20), (639,21), (639,22), (639,23),
14+
(638,23), (637,23), (637,22), (637,21), (636,21), (635,21), (635,20), (635,19), (636,19), (634,19),
15+
(633,19), (633,20), (633,21), (633,22), (633,23), (634,23), (635,23), (635,24), (635,25), (634,25),
16+
(633,25), (633,26), (633,27), (633,28), (633,29), (633,30), (633,31), (634,31), (635,31), (635,30),
17+
(635,29), (636,29), (637,29), (637,28), (637,27), (636,27), (637,26), (637,25), (638,25), (639,25),
18+
(639,26), (639,27), (639,28), (639,29), (639,30), (639,31), (639,32), (639,33), (638,33), (637,33),
19+
(637,32), (637,34), (637,35), (637,36), (637,37), (637,38), (637,39), (638,39), (639,39), (639,38),
20+
(639,40), (639,41), (639,42), (639,43), (638,43), (637,43), (637,44), (637,45), (637,46), (637,47),
21+
(638,47), (639,47), (639,46), (639,48), (639,49), (639,50), (639,51), (638,51), (637,51), (637,50),
22+
(637,49), (636,49), (635,49), (635,50), (635,51), (634,51), (633,51), (633,52), (633,53), (634,53),
23+
(635,53), (635,54), (635,55), (636,55), (637,55), (637,54), (637,53), (638,53), (639,53), (639,54),
24+
(639,55), (639,56), (639,57), (638,57), (637,57), (636,57), (635,57), (635,58), (635,59), (636,59),
25+
(637,59), (637,60), (637,61), (636,61), (635,61), (635,62), (635,63), (635,64), (635,65), (635,66),
26+
(635,67), (636,67), (637,67), (637,66), (637,65), (638,65), (639,65), (639,64), (639,66), (639,67),
27+
(639,68), (639,69), (638,69), (637,69), (636,69), (635,69), (634,69), (633,69), (633,70), (633,71),
28+
(633,72), (633,73), (634,73), (635,73), (636,73), (637,73), (637,74), (637,75), (638,75), (639,75),
29+
(639,74), (639,76), (639,77), (638,77), (637,77), (637,78), (637,79), (637,80), (637,81), (637,82),
30+
(637,83), (636,83), (635,83), (635,84), (635,85), (636,85), (637,85), (637,86), (637,87), (637,88),
31+
(637,89), (636,89), (635,89), (634,89), (633,89), (633,88), (633,87), (634,87), (633,86), (633,85),
32+
(633,84), (633,83), (633,82), (633,81), (632,81), (631,81), (631,82), (631,83), (630,83), (629,83),
33+
(629,82), (629,81), (629,80), (629,79), (630,79), (631,79), (632,79), (633,79), (633,78), (633,77),
34+
(632,77), (631,77), (631,76), (631,75), (632,75), (630,75), (629,75), (629,74), (629,73), (629,72),
35+
(629,71), (628,71), (627,71), (627,72), (627,73), (626,73), (625,73), (625,72), (625,71), (625,70),
36+
(625,69), (626,69), (627,69), (628,69), (629,69), (629,68), (629,67), (630,67), (631,67), (632,67),
37+
(631,68), (631,69), (631,70), (631,71), (631,72), (631,73)]
38+
file_path="maze/maze.png"
39+
first_step(ary,file_path)
40+
41+
42+
deffirst_step(ary,file_path):
43+
maze=Image.open(file_path)
44+
way=Image.new("RGBA",maze.size, (255,255,255,255))
45+
way_drawer=ImageDraw.Draw(way)
46+
forpointinary:
47+
way_drawer.point(point,maze.getpixel((point)))
48+
way.show()
49+
50+
51+
if__name__=="__main__":
52+
main()

‎24.py

Lines changed: 56 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -31,45 +31,55 @@ def second_step(im, height):
3131
defthird_step(im,start,width,height):
3232
x=start[0]
3333
y=start[1]
34+
point_ary= [(x,y)]
3435
way="0"
35-
max_key=int(way)
36-
ok_points= [(x,y)]
37-
ok_points_dic= {way:ok_points}
38-
one_way(im,x,y,ok_points_dic,max_key)
39-
40-
41-
defone_way(im,x,y,ok_points_dic,max_key):
42-
whileTrue:
43-
logging.debug("ok_points_dic={}".format(ok_points_dic))
44-
keys=ok_points_dic.keys()
45-
to_be_delete=set()
46-
to_be_add_dict=dict()
47-
forwayinkeys:
48-
way_ok_points=ok_points_dic.get(way)
49-
next_points=find_next_point(im,x,y,way_ok_points,way)
50-
ifnext_pointsisNone:
51-
logging.debug("break code 1")
52-
to_be_delete.add(way)
53-
logging.debug("add way={} to be delete, because next_points is None".format(way))
54-
break
55-
else:
56-
forpointinnext_points:
57-
max_key+=1
58-
to_be_delete.add(way)
59-
logging.debug("add way={}to to be delete, because create a new one={}".format(way,max_key))
60-
to_be_add_dict[str(max_key)]=way_ok_points
61-
x=point[0]
62-
y=point[1]
63-
new_points=to_be_add_dict.get(str(max_key))
64-
new_points.append((x,y))
65-
to_be_add_dict[str(max_key)]=new_points
66-
forkeyinto_be_add_dict.keys():
67-
ok_points_dic[key]=to_be_add_dict[key]
68-
forelementinto_be_delete:
69-
delok_points_dic[element]
70-
71-
72-
deffind_next_point(im,x,y,ok_points,way):
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))
7383
right_x=x+1
7484
left_x=x-1
7585
up_y=y-1
@@ -95,28 +105,29 @@ def find_next_point(im, x, y, ok_points, way):
95105
left_point=left_x,y
96106
up_point=x,up_y
97107
down_point=x,down_y
108+
next_director= {}
98109
ifright_x_pixelisnotNoneandright_x_pixel!= (255,255,255,255):
99-
print("right_x={}, y={}, right_x_pixel={}".format(right_x,y,right_x_pixel))
110+
logging.info("right_x={}, y={}, right_x_pixel={}".format(right_x,y,right_x_pixel))
100111
points.append(right_point)
101112
ifleft_x_pixelisnotNoneandleft_x_pixel!= (255,255,255,255):
102-
print("left_x={}, y={}, left_x_pixel={}".format(left_x,y,left_x_pixel))
113+
logging.info("left_x={}, y={}, left_x_pixel={}".format(left_x,y,left_x_pixel))
103114
points.append(left_point)
104115
ifup_y_pixelisnotNoneandup_y_pixel!= (255,255,255,255):
105-
print("x={}, up_y={}, up_y_pixel={}".format(x,up_y,up_y_pixel))
116+
logging.info("x={}, up_y={}, up_y_pixel={}".format(x,up_y,up_y_pixel))
106117
points.append(up_point)
107118
ifdown_y_pixelisnotNoneanddown_y_pixel!= (255,255,255,255):
108-
print("x={}, down_y={}, down_y_pixel={}".format(x,down_y,down_y_pixel))
119+
logging.info("x={}, down_y={}, down_y_pixel={}".format(x,down_y,down_y_pixel))
109120
points.append(down_point)
110-
logging.debug("way={}, x={}, y={}, right_x_pixel={}, left_x_pixel={}, up_y_pixel={}, down_y_pixel={}".format(way,x,y,right_x_pixel,left_x_pixel,
111-
up_y_pixel,down_y_pixel))
112121
forpointinpoints:
113122
now_index=ok_points.index((x,y))
114123
before=ok_points[now_index-1]
115124
ifbefore==point:
125+
logging.info("removing {}".format(point))
116126
points.remove(point)
117127
iflen(points)<1:
118-
# print("points为None,x={}, y={}".format(x, y))
128+
logging.info("return None")
119129
returnNone
130+
logging.info("return points={}".format(points))
120131
returnpoints
121132

122133

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp