e2D 1.3.3__py3-none-any.whl → 1.3.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- e2D/plots.py +134 -19
- {e2D-1.3.3.dist-info → e2D-1.3.5.dist-info}/METADATA +1 -1
- e2D-1.3.5.dist-info/RECORD +9 -0
- e2D-1.3.3.dist-info/RECORD +0 -9
- {e2D-1.3.3.dist-info → e2D-1.3.5.dist-info}/LICENSE +0 -0
- {e2D-1.3.3.dist-info → e2D-1.3.5.dist-info}/WHEEL +0 -0
- {e2D-1.3.3.dist-info → e2D-1.3.5.dist-info}/top_level.txt +0 -0
e2D/plots.py
CHANGED
|
@@ -9,10 +9,11 @@ def no_error_complex_function(function, args) -> V2|Vector2D:
|
|
|
9
9
|
sign = lambda value: -1 if value < 0 else (1 if value > 0 else 0)
|
|
10
10
|
|
|
11
11
|
class Function:
|
|
12
|
-
def __init__(self, function,
|
|
13
|
-
self.plot
|
|
12
|
+
def __init__(self, function, color) -> None:
|
|
13
|
+
self.plot : Plot
|
|
14
14
|
self.color = color
|
|
15
|
-
self.
|
|
15
|
+
self.function = function
|
|
16
|
+
self.__layer_surface__ :pg.Surface= None #type: ignore
|
|
16
17
|
|
|
17
18
|
def update_points(self) -> None:
|
|
18
19
|
self.update_function(self.function)
|
|
@@ -25,11 +26,25 @@ class Function:
|
|
|
25
26
|
def update_function(self, new_function) -> None:
|
|
26
27
|
self.function = new_function
|
|
27
28
|
self.points = self.get_points()
|
|
29
|
+
self.render()
|
|
30
|
+
|
|
31
|
+
def render(self) -> None:
|
|
32
|
+
self.__layer_surface__.fill((0,0,0,0))
|
|
33
|
+
offset = self.plot.dragging - self.plot.start_dragging if (self.plot.dragging != None) and (not self.plot.settings.get("use_real_time_rendering")) else None
|
|
34
|
+
if any(x < 1 for x in self.plot.scale):
|
|
35
|
+
for point in self.points:
|
|
36
|
+
# radius = max(min(self.plot.pixel_size)*.5, 1)
|
|
37
|
+
# pg.draw.circle(self.plot.canvas, self.color, (point + self.plot.pixel_size*.5)(), radius)
|
|
38
|
+
pg.draw.rect(self.__layer_surface__, self.color, (point.tolist() + (offset if offset != None else V2z))() + self.plot.pixel_size()) #type: ignore
|
|
39
|
+
else:
|
|
40
|
+
for point in self.points:
|
|
41
|
+
point = point.astype(int).tolist()
|
|
42
|
+
if self.plot.dragging != None:
|
|
43
|
+
point = round(point + offset)()
|
|
44
|
+
self.__layer_surface__.set_at(point, self.color)
|
|
28
45
|
|
|
29
46
|
def draw(self) -> None:
|
|
30
|
-
|
|
31
|
-
for point in self.points:
|
|
32
|
-
self.plot.canvas.set_at(list(map(int, point)), self.color)
|
|
47
|
+
self.plot.canvas.blit(self.__layer_surface__, (0,0))
|
|
33
48
|
|
|
34
49
|
# class ComplexFunction:
|
|
35
50
|
# def __init__(self, function, plot:"Plot", starting_t:float=-10, ending_t:float=10, step=.01, color=(255,255,255), auto_connect_treshold=float("inf"), points_radius=2, points_color=None) -> None:
|
|
@@ -65,6 +80,55 @@ class Function:
|
|
|
65
80
|
# if point.distance_to(self.points[i]) < self.auto_connect_treshold:
|
|
66
81
|
# pg.draw.line(self.plot.canvas, self.color, real_points[i], real_point) #type: ignore
|
|
67
82
|
|
|
83
|
+
class __PlotSettings__:
|
|
84
|
+
def __init__(self, plot:Plot) -> None:
|
|
85
|
+
self.plot = plot
|
|
86
|
+
self.settings :dict= {
|
|
87
|
+
"use_real_time_rendering" : True,
|
|
88
|
+
"show_corners_coords" : True,
|
|
89
|
+
|
|
90
|
+
"use_inter_pixel_correction" : True,
|
|
91
|
+
|
|
92
|
+
"show_zoom_info": True,
|
|
93
|
+
"top_left_info_position" : self.plot.position + V2(20, 100),
|
|
94
|
+
"info_spacing" : V2(0, 32),
|
|
95
|
+
"info_precision" : 2,
|
|
96
|
+
|
|
97
|
+
"distance_to_axis_for_scalar_zoom" : 10,
|
|
98
|
+
|
|
99
|
+
"bg_color" : (25, 25, 25),
|
|
100
|
+
"axes_default_color" : (100, 100, 100),
|
|
101
|
+
"x_axis_color" : None,
|
|
102
|
+
"y_axis_color" : None,
|
|
103
|
+
|
|
104
|
+
"axes_default_width" : 5,
|
|
105
|
+
"x_axis_width" : None,
|
|
106
|
+
"y_axis_width" : None,
|
|
107
|
+
|
|
108
|
+
"show_cursor_coords" : False,
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
def print_current_settings(self) -> None:
|
|
112
|
+
longest_key = max(map(len, self.settings))
|
|
113
|
+
longest_type = max(map(lambda setting: len(str(type(setting)).split("'")[1]), self.settings.values()))
|
|
114
|
+
split_string = '"'
|
|
115
|
+
for setting in self.settings:
|
|
116
|
+
print(f"{setting}{' '*(longest_key-len(setting))} :{str(type(self.settings[setting])).split(split_string)[1]}{' '*(longest_type-len(str(type(self.settings[setting])).split(split_string)[1]))}=\t{self.settings[setting]}")
|
|
117
|
+
|
|
118
|
+
def set(self, key:str, new_value) -> None:
|
|
119
|
+
if not (key in self.settings): raise ValueError(f"The key [{key}] does not exist...")
|
|
120
|
+
self.settings[key] = new_value
|
|
121
|
+
|
|
122
|
+
def multiple_set(self, keys:list[str], new_values:list) -> None:
|
|
123
|
+
for key, new_value in zip(keys, new_values):
|
|
124
|
+
self.set(key, new_value)
|
|
125
|
+
|
|
126
|
+
def get(self, key:str) -> bool|V2|Vector2D|int|float:
|
|
127
|
+
return self.settings[key]
|
|
128
|
+
|
|
129
|
+
def multiple_get(self, keys:list[str]) -> list[bool|V2|Vector2D|int|float]:
|
|
130
|
+
return [self.get(key) for key in keys]
|
|
131
|
+
|
|
68
132
|
class Plot:
|
|
69
133
|
__top_left_multiplier__ = V2(1, -1)
|
|
70
134
|
__bottop_right_multiplier__ = V2(1, -1)
|
|
@@ -77,7 +141,9 @@ class Plot:
|
|
|
77
141
|
self.position = plot_position
|
|
78
142
|
self.size = plot_size
|
|
79
143
|
self.scale = scale
|
|
80
|
-
|
|
144
|
+
|
|
145
|
+
self.settings = __PlotSettings__(self)
|
|
146
|
+
|
|
81
147
|
self.current_zoom = V2one * -np.log2(10)*10
|
|
82
148
|
self.current_offset = V2(0,0)
|
|
83
149
|
self.update_grid(True)
|
|
@@ -86,6 +152,7 @@ class Plot:
|
|
|
86
152
|
|
|
87
153
|
self.canvas = pg.Surface(self.size())
|
|
88
154
|
self.dragging = None
|
|
155
|
+
self.start_dragging = V2z
|
|
89
156
|
self.is_mouse_in_rect = False
|
|
90
157
|
|
|
91
158
|
def set_borders_by_position_and_zoom(self) -> None:
|
|
@@ -100,8 +167,14 @@ class Plot:
|
|
|
100
167
|
self.step = (self.bottom_right_plot_coord - self.top_left_plot_coord) / self.size / self.scale
|
|
101
168
|
X, Y = np.arange(self.top_left_plot_coord.x, self.bottom_right_plot_coord.x, self.step.x), np.arange(self.top_left_plot_coord.y, self.bottom_right_plot_coord.y, self.step.y)
|
|
102
169
|
self.meshgrid = np.meshgrid(X, Y)
|
|
170
|
+
self.pixel_size = abs(self.size / (self.bottom_right_plot_coord - self.top_left_plot_coord) * (self.step * -1))
|
|
171
|
+
if self.settings.get("use_inter_pixel_correction"):
|
|
172
|
+
self.pixel_size += V2one
|
|
103
173
|
|
|
104
174
|
def load_function(self, function:Function) -> None:
|
|
175
|
+
function.plot = self
|
|
176
|
+
function.__layer_surface__ = pg.Surface(self.size(), pg.SRCALPHA, 32).convert_alpha()
|
|
177
|
+
function.update_function(function.function)
|
|
105
178
|
self.functions.append(function)
|
|
106
179
|
|
|
107
180
|
def __plot2real__(self, plot_position:V2|Vector2D) -> V2|Vector2D:
|
|
@@ -111,19 +184,40 @@ class Plot:
|
|
|
111
184
|
return (real_position - self.position) * (self.bottom_right_plot_coord - self.top_left_plot_coord) / self.size + self.top_left_plot_coord
|
|
112
185
|
|
|
113
186
|
def render(self) -> None:
|
|
114
|
-
self.canvas.fill((
|
|
115
|
-
if self.
|
|
116
|
-
|
|
117
|
-
|
|
187
|
+
self.canvas.fill(self.settings.get("bg_color")) #type: ignore
|
|
188
|
+
if self.top_left_x < 0 < self.bottom_right_x:
|
|
189
|
+
pg.draw.line(self.canvas,
|
|
190
|
+
self.settings.get("axes_default_color") if (x_color:=self.settings.get("x_axis_color"))==None else x_color, #type: ignore
|
|
191
|
+
self.__plot2real__(V2(0, self.top_left_y))(),
|
|
192
|
+
self.__plot2real__(V2(0, self.bottom_right_y))(),
|
|
193
|
+
self.settings.get("axes_default_width") if (x_width:=self.settings.get("x_axis_width"))==None else x_width) #type: ignore
|
|
194
|
+
if self.bottom_right_y < 0 < self.top_left_y:
|
|
195
|
+
pg.draw.line(self.canvas,
|
|
196
|
+
self.settings.get("axes_default_color") if (y_color:=self.settings.get("y_axis_color"))==None else y_color, #type: ignore
|
|
197
|
+
self.__plot2real__(V2(self.top_left_x, 0))(),
|
|
198
|
+
self.__plot2real__(V2(self.bottom_right_x, 0))(),
|
|
199
|
+
self.settings.get("axes_default_width") if (y_width:=self.settings.get("y_axis_width"))==None else y_width) #type: ignore
|
|
200
|
+
|
|
118
201
|
for function in self.functions: function.draw()
|
|
119
202
|
|
|
120
203
|
pg.draw.rect(self.canvas, (255,255,255), V2z() + self.size(), 5) #type: ignore
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
204
|
+
|
|
205
|
+
center = self.size * .5
|
|
206
|
+
aimer_radius = 15
|
|
207
|
+
pg.draw.line(self.canvas, (100,100,100), (center + aimer_radius)(), (center - aimer_radius)(), 1)
|
|
208
|
+
pg.draw.line(self.canvas, (100,100,100), (center + self.__top_left_multiplier__ * aimer_radius)(), (center - self.__top_left_multiplier__ * aimer_radius)(), 1)
|
|
209
|
+
pg.draw.circle(self.canvas, (100,100,100), (self.size * .5)(), 15, 1)
|
|
210
|
+
|
|
211
|
+
if self.settings.get("show_corners_coords"):
|
|
212
|
+
self.rootEnv.print(str(self.top_left_plot_coord.__round__(.1)), V2z.copy(), bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
|
|
213
|
+
self.rootEnv.print(str(V2(self.top_left_plot_coord.x, self.bottom_right_plot_coord.y).__round__(.1)), self.size * V2(0, 1), fixed_sides=TEXT_FIXED_SIDES_BOTTOM_LEFT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
|
|
214
|
+
self.rootEnv.print(str(self.bottom_right_plot_coord.__round__(.1)), self.size.copy(), fixed_sides=TEXT_FIXED_SIDES_BOTTOM_RIGHT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
|
|
215
|
+
self.rootEnv.print(str(V2(self.bottom_right_plot_coord.x, self.top_left_plot_coord.y).__round__(.1)), self.size * V2(1, 0), fixed_sides=TEXT_FIXED_SIDES_TOP_RIGHT, bg_color=(0,0,0), border_color=(255,255,255), border_width=2, border_radius=15, margin=V2(10,10), personalized_surface=self.canvas)
|
|
125
216
|
|
|
126
217
|
def update(self) -> None:
|
|
218
|
+
self.plot_mouse_position = self.__real2plot__(self.rootEnv.mouse.position)
|
|
219
|
+
self.plot_center_real_position = self.__plot2real__(V2z) + self.position
|
|
220
|
+
|
|
127
221
|
self.is_mouse_in_rect = self.position.x < self.rootEnv.mouse.position.x < self.position.x + self.size.x and \
|
|
128
222
|
self.position.y < self.rootEnv.mouse.position.y < self.position.y + self.size.y
|
|
129
223
|
|
|
@@ -133,11 +227,16 @@ class Plot:
|
|
|
133
227
|
for function in self.functions:
|
|
134
228
|
function.update_points()
|
|
135
229
|
self.render()
|
|
230
|
+
|
|
136
231
|
|
|
137
232
|
if self.is_mouse_in_rect:
|
|
138
233
|
for event in self.rootEnv.events:
|
|
139
234
|
if event.type == pg.MOUSEWHEEL:
|
|
140
|
-
|
|
235
|
+
|
|
236
|
+
range_n = self.settings.get("distance_to_axis_for_scalar_zoom")
|
|
237
|
+
scalar = V2(0 if abs(self.plot_center_real_position.x - self.rootEnv.mouse.position.x) < range_n else 1, 0 if abs(self.plot_center_real_position.y - self.rootEnv.mouse.position.y) < range_n else 1) #type: ignore
|
|
238
|
+
self.current_zoom += event.y * scalar
|
|
239
|
+
|
|
141
240
|
self.update_grid(True)
|
|
142
241
|
for function in self.functions:
|
|
143
242
|
function.update_points()
|
|
@@ -145,15 +244,31 @@ class Plot:
|
|
|
145
244
|
|
|
146
245
|
if self.rootEnv.mouse.just_pressed[0] and self.dragging == None:
|
|
147
246
|
self.dragging = self.rootEnv.mouse.position.copy()
|
|
247
|
+
self.start_dragging = self.dragging.copy()
|
|
148
248
|
|
|
149
249
|
if self.dragging:
|
|
150
250
|
offset = (self.dragging - self.rootEnv.mouse.position)* V2(1, -1) * (abs(self.bottom_right_plot_coord - self.top_left_plot_coord) / self.size)
|
|
151
251
|
self.dragging = self.rootEnv.mouse.position.copy()
|
|
152
252
|
self.current_offset += offset
|
|
153
|
-
|
|
253
|
+
|
|
254
|
+
if self.settings.get("use_real_time_rendering"):
|
|
255
|
+
self.update_grid(True)
|
|
256
|
+
for function in self.functions: function.update_points()
|
|
257
|
+
else:
|
|
258
|
+
self.update_grid()
|
|
154
259
|
self.render()
|
|
155
260
|
|
|
156
261
|
def draw(self) -> None:
|
|
157
262
|
self.rootEnv.screen.blit(self.canvas, self.position())
|
|
158
|
-
if self.is_mouse_in_rect:
|
|
159
|
-
self.rootEnv.print(str(round(self.
|
|
263
|
+
if self.is_mouse_in_rect and self.settings.get("show_cursor_coords"):
|
|
264
|
+
self.rootEnv.print(str(round(self.plot_mouse_position, .1)), self.rootEnv.mouse.position, fixed_sides=TEXT_FIXED_SIDES_BOTTOM_MIDDLE) #type: ignore
|
|
265
|
+
|
|
266
|
+
data = [
|
|
267
|
+
[f"ZOOM:", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
|
|
268
|
+
[f" x: {self.current_zoom.x:.{self.settings.get('info_precision')}f};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
|
|
269
|
+
[f" y: {self.current_zoom.y:.{self.settings.get('info_precision')}f};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
|
|
270
|
+
]
|
|
271
|
+
|
|
272
|
+
for i, (d, fixed_side, show) in enumerate(data):
|
|
273
|
+
if show:
|
|
274
|
+
self.rootEnv.print(d, self.settings.get("top_left_info_position") + self.settings.get("info_spacing") * i, fixed_sides=fixed_side) #type: ignore
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e2D
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.5
|
|
4
4
|
Summary: Python library for 2D games. Streamlines dev with keyboard/mouse input, vector calculations, color manipulation, and collision detection. Simplify game creation and unleash creativity!
|
|
5
5
|
Home-page: https://github.com/marick-py/e2D
|
|
6
6
|
Author: Riccardo Mariani
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
e2D/__init__.py,sha256=1aJPqvWfZmIB_Ti7RaPX7KrHULha3VQe_ulsowcNqO8,58309
|
|
2
|
+
e2D/envs.py,sha256=mhq3SI2EmckXp9h6RYKzTGSKkvzlH-SyMTBhl3yDVZU,3929
|
|
3
|
+
e2D/plots.py,sha256=leq6KUTaiIBQCYfn8ksOAd6Y8LKTbXutMDd9_SaCpJ4,15186
|
|
4
|
+
e2D/utils.py,sha256=sq9efoNnSlJAfjvf18qDQpvO1jyz-9-mWBW3P4WMkD4,5368
|
|
5
|
+
e2D-1.3.5.dist-info/LICENSE,sha256=wymkNVDvj3qmjdO_rAhkRPM4t5y3_SqffGsFdgfvznU,1066
|
|
6
|
+
e2D-1.3.5.dist-info/METADATA,sha256=exsNCqNEUrbxasah6uqwfpFtV-Ee4vOMSLm1LZWNwxs,9608
|
|
7
|
+
e2D-1.3.5.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
8
|
+
e2D-1.3.5.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
|
|
9
|
+
e2D-1.3.5.dist-info/RECORD,,
|
e2D-1.3.3.dist-info/RECORD
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
e2D/__init__.py,sha256=1aJPqvWfZmIB_Ti7RaPX7KrHULha3VQe_ulsowcNqO8,58309
|
|
2
|
-
e2D/envs.py,sha256=mhq3SI2EmckXp9h6RYKzTGSKkvzlH-SyMTBhl3yDVZU,3929
|
|
3
|
-
e2D/plots.py,sha256=BOfWFsezpYtLv-33gHY48WnEineiW8gLlsxKRfcemNc,9154
|
|
4
|
-
e2D/utils.py,sha256=sq9efoNnSlJAfjvf18qDQpvO1jyz-9-mWBW3P4WMkD4,5368
|
|
5
|
-
e2D-1.3.3.dist-info/LICENSE,sha256=wymkNVDvj3qmjdO_rAhkRPM4t5y3_SqffGsFdgfvznU,1066
|
|
6
|
-
e2D-1.3.3.dist-info/METADATA,sha256=b1xbCyKlMK0RNSlDbXy6JYeVeyae37cGbAKBcDs2u6Q,9608
|
|
7
|
-
e2D-1.3.3.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
|
8
|
-
e2D-1.3.3.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
|
|
9
|
-
e2D-1.3.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|