-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdraw_labyrinth.py
More file actions
125 lines (91 loc) · 3.99 KB
/
draw_labyrinth.py
File metadata and controls
125 lines (91 loc) · 3.99 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
114
115
116
117
118
119
120
from pyray import *
from raylib import *
SOFTBLACK = (68, 68, 68, 120)
class Mesh:
def __init__(self, width, height, reason, horizontal_quantity, vertical_quantity, radius, color):
self.quotient = width / height
self.reason = reason
self.quantity = [horizontal_quantity - 1, vertical_quantity - 1]
self.width = width * reason
self.height = self.width / self.quotient
print(f"{self.width}, {self.height}")
self.x0 = 0.5 * (width - self.width)
self.y0 = 0.5 * (height - self.height)
#self.points_position = list()
self.radius = radius
self.color = color
self.points = list()
self.sides = list()
def determine_position_points(self):
edge_horizontal = self.width / self.quantity[0]
edge_height = self.height / self.quantity[1]
x = [self.x0 + iterator * edge_horizontal for iterator in range(self.quantity[0] + 1)]
y = [self.y0 + iterator * edge_height for iterator in range(self.quantity[1] + 1)]
"""for i in range(x):
row = [[x[i], y[j]] for j in range(y)]
self.points_position.append(row)"""
for pos_x in x:
for pos_y in y:
point = Point(pos_x, pos_y, self.radius, self.color)
self.points.append(point)
"""rows = [[point = Point(pos_x, pos_y, self.radius, self.color) for pos_y in y] for pos_x in x]
for row in rows:
self.points_position.extend(row)"""
def draw_mesh(self):
"""for pos in self.points_position:
draw_circle(int(pos[0]), int(pos[1]), int(self.radius), self.color)"""
for point in self.points:
point.draw_point()
def view_state_point(self, state_points):
indices = []
for iterator, state in enumerate(state_points):
if state == "True":
indices.append(iterator)
if len(indices) == 2:
for point in self.points:
point.selected = False
point.color = SOFTBLACK
print(", ".join([str(point.selected) for point in self.points]))
side = Side(self.points[indices[0]], self.points[indices[1]], MAGENTA)
self.sides.append(side)
def detect_selected(self):
for point in self.points:
point.detect_selected()
def draw_sides(self):
for side in self.sides:
side.draw_side()
class Side:
def __init__(self, initial_point, final_point, color):
self.points = [initial_point, final_point]
self.color = color
def draw_side(self):
draw_line(int(self.points[0].position[0]), int(self.points[0].position[1]), int(self.points[1].position[0]), int(self.points[1].position[1]), self.color)
class Point:
def __init__(self, x, y, radius, color):
self.position = [x, y]
self.radius = radius
self.color = color
self.selected = False
def draw_point(self):
draw_circle(int(self.position[0]), int(self.position[1]), int(self.radius), self.color)
def detect_selected(self):
if is_mouse_button_down(MOUSE_BUTTON_LEFT) and (get_mouse_x() - self.position[0]) ** 2 + (get_mouse_y() - self.position[1]) ** 2 <= self.radius ** 2:
self.selected = True
self.color = RED
def main():
window_width = 700
window_height = 500
mesh = Mesh(window_width, window_height, 0.8, 21, 15, 5, SOFTBLACK)
mesh.determine_position_points()
init_window(window_width, window_height, "Labyrinth")
while not window_should_close():
begin_drawing()
mesh.draw_mesh()
mesh.detect_selected()
state_points = [str(point.selected) for point in mesh.points]
mesh.draw_sides()
mesh.view_state_point(state_points) # Llamar a view_state_point después de draw_sides
clear_background(BLACK)
end_drawing()
close_window()
main()