-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbejaro_terv.py
153 lines (132 loc) · 4.78 KB
/
bejaro_terv.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
import math
import logging
import time
from PIL import Image, ImageDraw
import copy
import pygame
def debug(str,var):
print(str)
print(var)
def distance(start_point, end_point):
return math.dist(start_point, end_point)
def nearest_point(start_point, array):
debug("start point:", start_point)
start_point = [start_point[0], start_point[1]]
distances_array = []
for i in array:
distances_array.append(distance(start_point, [i[0], i[1]]))
# print(min(distances_array))
return distances_array.index(min(distances_array))
def floodfill(going_over_coords, start_coord):
# (x,y)
actual_coord = start_coord
# (x,y,0)
going_over_coords_queue = copy.deepcopy(going_over_coords)
# debug("queue: ", going_over_coords_queue)
while len(going_over_coords_queue) != 0:
if actual_coord in going_over_coords_queue:
going_over_coords[going_over_coords.index(actual_coord)][2] = 1
bejaras.append(actual_coord)
going_over_coords_queue.remove(actual_coord)
if(len(going_over_coords_queue) != 0):
actual_coord = going_over_coords_queue[nearest_point(actual_coord, going_over_coords_queue)]
# print(actual_coord)
# print("bejaras: ", bejaras)
return bejaras
max_x_bejaras = 200
max_y_bejaras = 200
start_x = 0
start_y = 0
def draw_area(dis):
y = 0
x = 0
while y < max_y_bejaras + 100:
x = 0
while x < max_x_bejaras + 100:
if x == 0 or x == max_x_bejaras + 50 or y == 0 or y == max_y_bejaras + 50: # y == 150 and x > 150 or y == 200 and x > 150 or x == 0 or x == 350 or y == 0 or y == 350:
area_coords.append([x, y, 1])
# ImageDraw.Draw(img).rectangle([(x, y), (x + 50, y + 50)], fill="#FF0000", outline="green")
pygame.draw.rect(dis, "red", [x, y, 50, 50])
pygame.draw.rect(dis, "green", [x, y, 50, 50], 1)
pygame.display.update()
else:
# ImageDraw.Draw(img).rectangle([(x, y), (x + 50, y + 50)], fill="#FFFFFF", outline="green")
area_coords.append([x, y, 0])
pygame.draw.rect(dis, "white", [x, y, 50, 50])
pygame.draw.rect(dis, "green", [x, y, 50, 50], 1)
pygame.display.update()
if y > 0 and x > 0:
pygame.draw.circle(dis, "blue", [x, y], 5)
pygame.display.update()
going_over_coords.append([x, y, 0])
# if y == 200 and x > 200 or y == 200 and x > 200:
# ()
# else:
# ImageDraw.Draw(img).ellipse((x - 5, y - 5, x + 5, y + 5), fill="green", outline="white")
# pygame.draw.circle(dis, "blue", [x, y], 5)
# pygame.display.update()
# going_over_coords.append([x, y, 0])
x += 50
y += 50
w, h = max_x_bejaras + 100, max_y_bejaras + 100
x, y = 0, 0
shape = [(x, y), (50, 50)]
# creating new Image object
img = Image.new("RGB", (w, h))
# create rectangleimage
# ##valtozok a bejarashoz
# ##(x,y,color)
area_coords = []
start_coord = [start_x + 50, start_y + 50, 0]
# ##(x,y,color)
going_over_coords = []
bejaras = []
koordinates_output = []
# y = 0
# x = 0
# while y < 400:
# x = 0
# while x < 400:
# if y == 150 and x > 150 or y == 200 and x > 150 or x == 0 or x == 350 or y == 0 or y == 350:
# area_coords.append([x, y, 1])
# ImageDraw.Draw(img).rectangle([(x, y), (x + 50, y + 50)], fill="#FF0000", outline="green")
# else:
# ImageDraw.Draw(img).rectangle([(x, y), (x + 50, y + 50)], fill="#FFFFFF", outline="green")
# area_coords.append([x, y, 0])
# if y > 0 and x > 0:
# if y == 200 and x > 200 or y == 200 and x > 200:
# ()
# else:
# ImageDraw.Draw(img).ellipse((x - 5, y - 5, x + 5, y + 5), fill="green", outline="white")
# going_over_coords.append([x, y, 0])
#
# x += 50
# y += 50
#
# print(area_coords)
# print(going_over_coords)
# img.show()
#
# floodfill(going_over_coords, start_coord)
#
#
#
#
import pygame
pygame.init()
dis = pygame.display.set_mode((max_x_bejaras + 100, max_y_bejaras + 100))
draw_area(dis)
bejaras = floodfill(going_over_coords, start_coord)
game_over = False
while not game_over:
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
while len(bejaras) != 0:
print(bejaras[0][0], bejaras[0][1])
koordinates_output.append([bejaras[0][0] - 50, bejaras[0][1] - 50])
pygame.draw.circle(dis, "yellow", [bejaras[0][0], bejaras[0][1]], 5)
pygame.display.update()
bejaras.pop(0)
pygame.time.wait(1000)
print(koordinates_output)