-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
680 lines (591 loc) · 24.1 KB
/
main.py
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
import shutil
import sys
import random
import pygame.event
from Wave_algorythm import *
from consts import *
from history import Log, image_handling
from tkinter import filedialog
reversed = False
for dirs, folders, files in os.walk(path):
if not reversed:
files.reverse()
fil_len = len(files)
reversed = True
# С помощью этой функции создается стартовая точка
def starting(event):
global start_pos, start_pos_flag
if event.type == pygame.MOUSEBUTTONDOWN and ALLOWED_X[0] < pygame.mouse.get_pos()[0] < ALLOWED_X[1]:
start_pos = event.pos
DOTS_S.play()
start_pos_flag = True
# С помощью этой функции создается конечная точка
def ending(event):
global end_pos, end_pos_flag
if event.type == pygame.MOUSEBUTTONDOWN and ALLOWED_X[0] < pygame.mouse.get_pos()[0] < ALLOWED_X[1]:
end_pos = event.pos
DOTS_S.play()
end_pos_flag = True
# Проверка позоций стартовой и конечной точек на корректность
def check_pos_on_valid():
global end_pos, start_pos
if start_pos is not None:
while SCREEN.get_at(start_pos) == YELLOW:
start_pos = get_random_tuple()
if end_pos is not None:
color = SCREEN.get_at(end_pos)
while color == YELLOW:
end_pos = get_random_tuple()
color = SCREEN.get_at(end_pos)
# С помощью этой функции происходит рисование линий на экране
def drawing(e):
global mode, DELAY
pressed = pygame.mouse.get_pressed()
pos = pygame.mouse.get_pos()
if mode == LINES:
drawing_lines(e, pos)
else: # Eraser mode
if pressed[0]:
pygame.draw.circle(SCREEN, LIGHT_GRAY, pos, SCALE * 2)
DELAY += 1
if DELAY % 10 == 0:
ERASER_S.play()
DELAY = 0
# Функция для смены режима:
# Eraser mode <-> Lines mode
def change_mode():
global mode
if len(dots) != 0:
link_dots()
if mode == LINES:
mode = ERASER
else:
mode = LINES
# С помощью этой функции ставятся и соединяются точки на графе
def drawing_lines(e, p):
if e.type == pygame.MOUSEBUTTONDOWN:
button = e.button
if button == 1:
dots.append(p)
pygame.draw.circle(SCREEN, YELLOW, p, HALF_SCALE)
DOTS_LINES_S.play()
elif button == 3 and len(dots) >= 2:
link_dots()
# Функция, соединяющая точки на графе
def link_dots():
if len(dots) == 0:
return
if len(dots) == 1:
dots.append(get_random_tuple())
pygame.draw.lines(SCREEN, YELLOW, False, dots, SCALE * LINES_SCALE)
dots.clear()
LINES_S.play()
# Функция для обработки кнопок и обновления экрана
def check_on_close():
for e in pygame.event.get():
buttons_and_events(e)
pygame.display.update()
# Функция для обновления поля
def restart():
global start_pos_flag, start_pos, end_pos, end_pos_flag, \
default_end_pos, default_start_pos, dots, mode, objects, \
phase_drawing, ground_color, logs, log_page_number, saved, fil_len, files, log_page_counter
pygame.mixer.music.stop()
UPDATE_S.play()
start_pos = None
phase_drawing = True
start_pos_flag = False
end_pos = None
ground_color = None
end_pos_flag = False
default_start_pos = (SCALE * 2, SCALE * 2)
default_end_pos = (WINDOW_WIDTH - SCALE * 2, HEIGHT - SCALE * 2)
dots = []
mode = LINES
objects = []
logs.clear()
log_page_number = 0
log_page_counter = 1
saved = False
reversed = False
files.clear()
for dirs, folders, files in os.walk(path):
if not reversed:
files.reverse()
fil_len = len(files)
reversed = True
run()
# Функция для завершения работы приложения
def close(e):
if e.type == pygame.QUIT:
sys.exit()
# Кнопка для перезапуска программы
def restart_button(event):
button_surf = pygame.Surface((150, 55))
text = FONT.render('RESTART', True, BLACK)
center = (800, 50)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
restart()
BUTTON_S.play()
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Проверка на соответствие цвета поверхности
def check_deviation(pix):
return pix != YELLOW and (ground_color[0] - DEVIATION * ground_color[0] <= pix[0] <=
ground_color[0] + DEVIATION * ground_color[0]) and \
(ground_color[1] - DEVIATION * ground_color[1] <= pix[1] <=
ground_color[1] + DEVIATION * ground_color[1]) and \
(ground_color[2] - DEVIATION * ground_color[2] <= pix[2] <=
ground_color[2] + DEVIATION * ground_color[2]) or pix == GREEN \
or pix == RED or pix == LIGHT_GRAY
# Функция для случайного заполнения поля
def randomizer_pos():
global start_pos, start_pos_flag, end_pos, end_pos_flag
if not start_pos_flag:
start_pos = (get_random_tuple())
start_pos_flag = True
if not end_pos_flag:
end_pos = (get_random_tuple())
end_pos_flag = True
DOTS_S.play()
check_pos_on_valid()
# Функция для случайног о заполнения массива точек
def get_random_tuple():
return (random.randint(0, WINDOW_WIDTH - SCALE),
random.randint(0, HEIGHT - SCALE))
# Функция для случайного заполнения экрана
def randomizer_dots():
for i in range(2, 4):
for j in range(i):
dots.append(get_random_tuple())
link_dots()
for i in range(2, 8):
for j in range(i):
pygame.draw.circle(SCREEN, YELLOW, get_random_tuple(), i)
# Кнопка для рисования
def draw_button(event):
button_surf = pygame.Surface((150, 55))
text = FONT.render('DRAW', True, BLACK)
center = (600, 150)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
if phase_drawing and not end_pos_flag:
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
if len(dots) == 0 or mode == ERASER:
randomizer_dots()
else:
link_dots()
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Функция для активации алгоритма поиска кратчайшего пути
def next_function():
global phase_drawing
if phase_drawing:
link_dots()
phase_drawing = False
BUTTON_S.play()
# Горячая клавиша для активации алгоритма поиска кратчайшего пути
def next_hotkey(event):
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
next_function()
# Кнопка для активации алгоритма поиска кратчайшего пути
def next_button(event):
button_surf = pygame.Surface((150, 55))
text = FONT.render('NEXT', True, BLACK)
center = (600, 50)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
if phase_drawing:
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
next_function()
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Кнопка для смены режима:
# Eraser mode <-> Lines mode
def mode_button(event):
button_surf = pygame.Surface((150, 55))
text = FONT.render(mode, True, BLACK)
center = (800, 150)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
if phase_drawing and not end_pos_flag:
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
change_mode()
BUTTON_S.play()
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Функция кнопки для загрузки изображений
def image_button(event):
global image_loaded
button_surf = pygame.Surface((150, 55))
text = FONT.render('IMAGE', True, BLACK)
center = (600, 250)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
if phase_drawing:
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
BUTTON_S.play()
try:
new_image = filedialog.askopenfilename(filetypes=[
('image', '*.jpeg*'),
('image', '*.jpg*'),
('image', '*.png*')
])
image_loading(new_image)
for dirs, folders, files in os.walk(path):
shutil.copy2(new_image, dirs)
image_loaded = True
except:
put_blank()
screen_text('Cannot upload the image', TEXT_X, TEXT_Y)
image_loaded = False
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Функция кнопки для перехода в журнал загруженных ранее или нарисованных пользователем изображений
def log_button(event):
global log_flag, log_page_number, fil_len
button_surf = pygame.Surface((150, 55))
text = FONT.render('LOG', True, BLACK)
center = (800, 250)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
if phase_drawing:
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
BUTTON_S.play()
log_flag = True
needed = files[log_page_number:log_page_number + 5]
for i in range(len(needed)):
if os.path.splitext(needed[i])[1] in allowed_splits:
obj = Log(dirs + '/' + needed[i], i, needed[i])
logs.append(obj)
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Функция кнопки для выхода из журнала загруженных изображений
def log_back_button(event):
global log_flag
button_surf = pygame.Surface((100, 35))
text = FONT.render('BACK', True, BLACK)
center = (850, 470)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
surf = pygame.Surface((400, 500))
surf.fill(GRAY)
surf_rect = surf.get_rect(center=(WINDOW_WIDTH + SETTINGS_WIDTH / 2, HEIGHT / 2))
if not end_pos_flag:
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
SCREEN.blit(surf, surf_rect)
log_flag = False
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Функция для отображения следующей страницы во вкладке истории
def log_next(event):
global log_page_number, log_flag, page_flag, fil_len
button_surf = pygame.Surface((50, 35))
text = FONT.render('>', True, BLACK)
center = (680, 470)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
surf = pygame.Surface((400, 500))
surf.fill(GRAY)
surf_rect = surf.get_rect(center=(WINDOW_WIDTH + SETTINGS_WIDTH / 2, HEIGHT / 2))
if not end_pos_flag:
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
SCREEN.blit(surf, surf_rect)
needed = files[log_page_number:log_page_number + 5]
for i in range(len(needed)):
if os.path.splitext(needed[i])[1] in allowed_splits:
obj = Log(dirs + '/' + needed[i], i, needed[i])
logs.append(obj)
page_flag = True
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Функция для отображения предыдущей страницы во вкладке истории
def log_prev(event):
global log_page_number, log_flag, prev_page, fil_len
button_surf = pygame.Surface((50, 35))
text = FONT.render('<', True, BLACK)
center = (620, 470)
text_rect = text.get_rect(center=center)
button = button_surf.get_rect(center=center)
button_surf.fill(WHITE)
mouse_pos = pygame.mouse.get_pos()
surf = pygame.Surface((400, 500))
surf.fill(GRAY)
surf_rect = surf.get_rect(center=(WINDOW_WIDTH + SETTINGS_WIDTH / 2, HEIGHT / 2))
if not end_pos_flag:
if button.collidepoint(mouse_pos):
button_surf.fill(LIGHT_GRAY)
if event.type == pygame.MOUSEBUTTONDOWN:
SCREEN.blit(surf, surf_rect)
needed = files[log_page_number:log_page_number + 5]
for i in range(len(needed)):
if os.path.splitext(needed[i])[1] in allowed_splits:
obj = Log(dirs + '/' + needed[i], i, needed[i])
logs.append(obj)
prev_page = True
else:
button_surf.fill(LIGHT_GRAY)
SCREEN.blit(button_surf, button)
SCREEN.blit(text, text_rect)
# Функция для случайного заполнения поля
def random_hotkey(event):
if event.type == pygame.KEYDOWN and event.key == pygame.K_r:
if phase_drawing:
randomizer_dots()
elif not phase_drawing:
randomizer_pos()
# функция загрузки изображения
def image_loading(filename):
SCREEN.blit(YELLOW_BLANK, (0, 0))
image = image_handling(pygame.image.load(filename))
SCREEN.blit(image, image.get_rect(center=(WINDOW_WIDTH // 2, HEIGHT // 2)))
# Функция для сохранения поля
def env_save():
global saved, image_loaded
if not image_loaded and not saved:
surf = pygame.Surface((WINDOW_WIDTH, HEIGHT))
surf_rect = surf.get_rect(center=(250, 250))
sub = SCREEN.subsurface(surf_rect)
pygame.image.save(sub, "logs/screenshot" + str(
random.randint(random.randint(1, 100), random.randint(1000, 10000))) + ".jpg")
saved = True
# Функция для вывода текста в специальное окошко
def screen_text(text, c_x, c_y):
scr_text = FONT.render(text, True, WHITE)
scr_text_rect = scr_text.get_rect(center=(c_x, c_y))
SCREEN.blit(scr_text, scr_text_rect)
# Функция для обновления текста на текстовом экране
def put_blank():
SCREEN.blit(BLANK, (525, 300))
pygame.draw.line(SCREEN, YELLOW, (525, 300), (875, 300), 5)
pygame.draw.line(SCREEN, YELLOW, (525, 475), (875, 475), 5)
# Функция для отображения номера текущей страницы из общего количества во вкладке истории
def page_number():
if fil_len % 5 == 0:
text = FONT.render(str(str(log_page_counter) + '/' + str(fil_len // 5)), True, WHITE)
text_rect = text.get_rect(center=(520, 470))
else:
text = FONT.render(str(str(log_page_counter) + '/' + str(fil_len // 5 + 1)), True, WHITE)
text_rect = text.get_rect(center=(520, 470))
SCREEN.blit(text, text_rect)
# Функция для обработки кнопок и событий
def buttons_and_events(event):
close(event)
global log_flag, log_page_number, page_flag, prev_page, image_loaded, fil_len, log_page_counter, files, needed
if not log_flag:
restart_button(event)
log_button(event)
random_hotkey(event)
draw_button(event)
next_button(event)
mode_button(event)
next_hotkey(event)
image_button(event)
else:
surf = pygame.Surface((400, 500))
surf.fill(DARK_GRAY)
surf_rect = surf.get_rect(center=(WINDOW_WIDTH + SETTINGS_WIDTH / 2, HEIGHT / 2))
SCREEN.blit(surf, surf_rect)
log_back_button(event)
if not log_flag:
SCREEN.blit(surf, surf_rect)
logs.clear()
put_blank()
for j in logs:
if not log_flag:
logs.clear()
put_blank()
break
j.display(event)
if j.clicked:
log_flag = False
SCREEN.blit(YELLOW_BLANK, (0, 0))
SCREEN.blit(surf, surf_rect)
SCREEN.blit(j.preview, j.preview_rect)
j.clicked = False
image_loaded = True
logs.clear()
put_blank()
screen_text('Draw the environment', TEXT_X, TEXT_Y)
break
if j.del_click:
logs.remove(j)
files.remove(j.filename[5:])
os.remove(j.filename)
fil_len = len(files)
if fil_len % 5 == 0:
if log_page_counter > (fil_len // 5):
log_page_number -= 5
log_page_counter -= 1
logs.clear()
needed = files[log_page_number:log_page_number + 5]
for i in range(len(needed)):
if os.path.splitext(needed[i])[1] in allowed_splits:
obj = Log(dirs + '/' + needed[i], i, needed[i])
logs.append(obj)
if log_page_number + 5 < fil_len:
log_next(event)
if log_page_number != 0:
log_prev(event)
if page_flag:
log_page_number += 5
log_page_counter += 1
SCREEN.blit(surf, surf_rect)
logs.clear()
log_next(event)
page_flag = False
break
elif prev_page:
log_page_number -= 5
log_page_counter -= 1
SCREEN.blit(surf, surf_rect)
logs.clear()
log_prev(event)
prev_page = False
break
page_number()
# Функция для запуска программы
def run():
global phase_drawing, ground_color
SCREEN.fill(LIGHT_GRAY)
pygame.display.update()
SCREEN.blit(SETTINGS, (WINDOW_WIDTH, 0))
put_blank()
screen_text('Draw the environment', TEXT_X, TEXT_Y)
pygame.display.update()
# Этап для установки начальной и конечной точек и рисования:
while not end_pos_flag:
CLOCK.tick(FPS)
for e in pygame.event.get():
buttons_and_events(e)
if ALLOWED_X[0] < pygame.mouse.get_pos()[0] < ALLOWED_X[1] and not log_flag:
# Отмечается стартовая точка и конечная точка;
if not start_pos_flag and not phase_drawing:
env_save()
starting(e)
pygame.draw.rect(SCREEN, YELLOW, (0, 0, SCALE, SCALE))
check_pos_on_valid()
elif not end_pos_flag and not phase_drawing:
ending(e)
pygame.draw.rect(SCREEN, YELLOW, (0, 0, SCALE, SCALE))
put_blank()
screen_text('Set finish position', TEXT_X, TEXT_Y)
check_pos_on_valid()
# Создаются препятствия
elif not start_pos_flag and not end_pos_flag:
put_blank()
screen_text('Draw the environment', TEXT_X, TEXT_Y)
drawing(e)
pygame.draw.rect(SCREEN, YELLOW, (0, 0, WINDOW_WIDTH, HEIGHT), SCALE)
if start_pos is not None and not log_flag:
if ground_color is None:
ground_color = SCREEN.get_at(start_pos)
SCREEN.blit(START, (start_pos[0] - SCALE, start_pos[1] - SCALE))
if end_pos is not None:
SCREEN.blit(END, (end_pos[0] - SCALE, end_pos[1] - SCALE))
pygame.display.update()
# Этап обработки поля в схему для
# последующей обработки алгоритмом
put_blank()
screen_text('Chart is handling...', TEXT_X, TEXT_Y)
pygame.display.update()
pygame.time.wait(1000)
scheme = [[None] * HEIGHT for _ in range(WINDOW_WIDTH)]
put_blank()
screen_text('Searching the shortest way...', TEXT_X, TEXT_Y)
pygame.display.update()
for x in range(0, WINDOW_WIDTH, COMPRESSION):
for y in range(0, HEIGHT, COMPRESSION):
check_on_close()
pix = SCREEN.get_at((x, y))
if check_deviation(pix):
scheme[x][y] = True
else:
scheme[x][y] = False
# Схема отправляется на обработку алгоритму
way = Wave_algorythm(scheme, (start_pos[0] // COMPRESSION, start_pos[1] // COMPRESSION),
(end_pos[0] // COMPRESSION,
end_pos[1] // COMPRESSION))
rect_hero = pygame.Rect(start_pos[0], start_pos[1], SCALE, SCALE)
pygame.display.update()
length = len(way)
# Обработка схемы движение и вывод кратчайшего пути на экран
if length:
put_blank()
screen_text('Drawing the shortest way...', TEXT_X, TEXT_Y)
pygame.display.update()
pygame.mixer.music.play(-1)
for i in way:
check_on_close()
pygame.draw.rect(SCREEN, ORANGE, rect_hero, SCALE, SCALE)
pygame.display.update(rect_hero)
rect_hero.x += i[0] * COMPRESSION
rect_hero.y += i[1] * COMPRESSION
pygame.time.wait(SCALE)
put_blank()
screen_text('The shortest way is drawn', TEXT_X, TEXT_Y - 20)
screen_text('Its length is ' + str(length * COMPRESSION) + ' pixels', TEXT_X, TEXT_Y + 30)
pygame.mixer.music.stop()
SUCCESS_S.play()
pygame.display.update()
else: # Алгоритм не смог вычислить кратчайший путь
put_blank()
screen_text('Sorry, but the algorithm', TEXT_X, TEXT_Y - 25)
screen_text('did not find the shortest way', TEXT_X, TEXT_Y + 25)
ERROR_S.play()
pygame.display.update()
# Конец работы программы и ожидание последующих действий
while 1:
check_on_close()
CLOCK.tick(FPS)
# Запуск программы
if __name__ == "__main__":
run()