e2D 1.3.10__tar.gz → 1.3.11__tar.gz
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-1.3.10 → e2D-1.3.11}/PKG-INFO +1 -1
- {e2D-1.3.10 → e2D-1.3.11}/e2D/__init__.py +26 -3
- {e2D-1.3.10 → e2D-1.3.11}/e2D/envs.py +4 -4
- {e2D-1.3.10 → e2D-1.3.11}/e2D/plots.py +18 -12
- {e2D-1.3.10 → e2D-1.3.11}/e2D.egg-info/PKG-INFO +1 -1
- {e2D-1.3.10 → e2D-1.3.11}/setup.cfg +1 -1
- {e2D-1.3.10 → e2D-1.3.11}/LICENSE +0 -0
- {e2D-1.3.10 → e2D-1.3.11}/README.md +0 -0
- {e2D-1.3.10 → e2D-1.3.11}/e2D/utils.py +0 -0
- {e2D-1.3.10 → e2D-1.3.11}/e2D.egg-info/SOURCES.txt +0 -0
- {e2D-1.3.10 → e2D-1.3.11}/e2D.egg-info/dependency_links.txt +0 -0
- {e2D-1.3.10 → e2D-1.3.11}/e2D.egg-info/requires.txt +0 -0
- {e2D-1.3.10 → e2D-1.3.11}/e2D.egg-info/top_level.txt +0 -0
- {e2D-1.3.10 → e2D-1.3.11}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e2D
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.11
|
|
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
|
|
@@ -15,7 +15,7 @@ DOUBLE_PI = PI*2
|
|
|
15
15
|
#
|
|
16
16
|
|
|
17
17
|
class Vector2D:
|
|
18
|
-
round_values_on_print :float=
|
|
18
|
+
round_values_on_print :int|float= 2
|
|
19
19
|
def __init__(self:"V2|Vector2D", x:int|float=0.0, y:int|float=0.0) -> None:
|
|
20
20
|
"""
|
|
21
21
|
# Initialize a 2D vector with the specified x and y components.
|
|
@@ -666,11 +666,25 @@ class Vector2D:
|
|
|
666
666
|
other = self.__normalize__(other)
|
|
667
667
|
return Vector2D(max(self.x, other.x), max(self.y, other.y))
|
|
668
668
|
|
|
669
|
+
def advanced_stringify(self:"V2|Vector2D", precision:float|None=None, use_scientific_notation:bool=False, return_as_list=False) -> str:
|
|
670
|
+
precision = self.round_values_on_print if precision == None else precision
|
|
671
|
+
def optimize(value) -> str:
|
|
672
|
+
abs_value = abs(value)
|
|
673
|
+
if abs_value < 1/10**precision and abs_value != 0:
|
|
674
|
+
return f"{value:.{precision}e}"
|
|
675
|
+
elif abs_value < 10**precision:
|
|
676
|
+
return f"{value:.{precision}f}".rstrip('0').rstrip('.')
|
|
677
|
+
else:
|
|
678
|
+
return f"{value:.{precision}e}"
|
|
679
|
+
if return_as_list:
|
|
680
|
+
return [optimize(self.x), optimize(self.y)] if use_scientific_notation else [f"{self.x:.{precision}f}" f"{self.y:.{precision}f}"]
|
|
681
|
+
return f"{optimize(self.x)}, {optimize(self.y)}" if use_scientific_notation else f"{self.x:.{precision}f}, {self.y:.{precision}f}"
|
|
682
|
+
|
|
669
683
|
def __str__(self:"V2|Vector2D") -> str:
|
|
670
|
-
return f"{self.x
|
|
684
|
+
return f"{self.x:.{self.round_values_on_print}f}, {self.y:.{self.round_values_on_print}f}"
|
|
671
685
|
|
|
672
686
|
def __repr__(self:"V2|Vector2D") -> str:
|
|
673
|
-
return f"x:{self.x
|
|
687
|
+
return f"x:{self.x:.{self.round_values_on_print}f}\ty:{self.y:.{self.round_values_on_print}f}"
|
|
674
688
|
|
|
675
689
|
def __call__(self:"V2|Vector2D", return_tuple=False) -> list|tuple:
|
|
676
690
|
return (self.x, self.y) if return_tuple else [self.x, self.y]
|
|
@@ -1250,3 +1264,12 @@ def distance_line_point(line_point_a:Vector2D|V2, line_point_b:Vector2D|V2, poin
|
|
|
1250
1264
|
The result is returned as a float representing the distance between the line segment and the point.
|
|
1251
1265
|
"""
|
|
1252
1266
|
return float(_np.linalg.norm(_np.cross((line_point_b-line_point_a)(), (line_point_a-point_c)()))/_np.linalg.norm((line_point_b-line_point_a)()))
|
|
1267
|
+
|
|
1268
|
+
def optimize_value_string(value:int|float, precision:int) -> str:
|
|
1269
|
+
abs_value = abs(value)
|
|
1270
|
+
if abs_value < 1/10**precision and abs_value != 0:
|
|
1271
|
+
return f"{value:.{precision}e}"
|
|
1272
|
+
elif abs_value < 10**precision:
|
|
1273
|
+
return f"{value:.{precision}f}".rstrip('0').rstrip('.')
|
|
1274
|
+
else:
|
|
1275
|
+
return f"{value:.{precision}e}"
|
|
@@ -22,9 +22,9 @@ while not rootEnv.quit:
|
|
|
22
22
|
|
|
23
23
|
pg.init()
|
|
24
24
|
pg.font.init()
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
FONT_ARIAL_16 = pg.font.SysFont("Arial", 16)
|
|
26
|
+
FONT_ARIAL_32 = pg.font.SysFont("Arial", 32)
|
|
27
|
+
FONT_ARIAL_64 = pg.font.SysFont("Arial", 64)
|
|
28
28
|
create_arial_font_size = lambda size: pg.font.SysFont("Arial", size)
|
|
29
29
|
|
|
30
30
|
TEXT_FIXED_SIDES_TOP_LEFT = 0
|
|
@@ -64,7 +64,7 @@ class RootEnv:
|
|
|
64
64
|
def clear_rect(self, position:V2|Vector2D, size:V2|Vector2D) -> None:
|
|
65
65
|
self.screen.fill(self.background_color, position() + size())
|
|
66
66
|
|
|
67
|
-
def print(self, text:str, position:V2|Vector2D, color:tuple[float,float,float]=(255,255,255), fixed_sides=TEXT_FIXED_SIDES_TOP_LEFT, font:pg.font.Font=
|
|
67
|
+
def print(self, text:str, position:V2|Vector2D, color:tuple[float,float,float]=(255,255,255), fixed_sides=TEXT_FIXED_SIDES_TOP_LEFT, font:pg.font.Font=FONT_ARIAL_32, bg_color:None|tuple[int,int,int]|list[int]=None, border_color:None|tuple[int,int,int]|list[int]=None, border_width:float=0, border_radius:int|list[int]|tuple[int,int,int,int]=-1, margin:V2|Vector2D=V2z, personalized_surface:pg.Surface|None=None) -> None:
|
|
68
68
|
text_box = font.render(text, True, color)
|
|
69
69
|
size = V2(*text_box.get_size()) + margin * 2
|
|
70
70
|
position = position - size * self.__fixed_sides_multiplier[fixed_sides] + margin
|
|
@@ -65,7 +65,7 @@ class PointsFunction(Function):
|
|
|
65
65
|
|
|
66
66
|
def render(self) -> None:
|
|
67
67
|
self.__layer_surface__.fill((0,0,0,0))
|
|
68
|
-
if len(self.plot_points): pg.draw.lines(self.__layer_surface__, self.color, False, self.plot_points)
|
|
68
|
+
if len(self.plot_points)>=2: pg.draw.lines(self.__layer_surface__, self.color, False, self.plot_points)
|
|
69
69
|
# for point in self.points:
|
|
70
70
|
# pg.draw.circle(self.__layer_surface__,
|
|
71
71
|
# self.points_color,
|
|
@@ -120,7 +120,6 @@ class __PlotSettings__:
|
|
|
120
120
|
"distance_to_axis_for_scalar_zoom" : 10,
|
|
121
121
|
|
|
122
122
|
# cursor
|
|
123
|
-
"show_cursor_coords" : False,
|
|
124
123
|
"zoom_on_center" : False,
|
|
125
124
|
|
|
126
125
|
# plot visual options
|
|
@@ -152,6 +151,9 @@ class __PlotSettings__:
|
|
|
152
151
|
"show_pointer" : True,
|
|
153
152
|
"pointer_radius" : 15,
|
|
154
153
|
"pointer_color" : rgb(255, 255, 255),
|
|
154
|
+
|
|
155
|
+
# cursor
|
|
156
|
+
"show_cursor_coords" : False,
|
|
155
157
|
|
|
156
158
|
#rect
|
|
157
159
|
"render_bg" : True,
|
|
@@ -163,8 +165,9 @@ class __PlotSettings__:
|
|
|
163
165
|
|
|
164
166
|
# info options
|
|
165
167
|
"show_zoom_info": True,
|
|
166
|
-
"top_left_info_position" : self.plot.position + V2(
|
|
167
|
-
"info_interline_space" : V2(0,
|
|
168
|
+
"top_left_info_position" : self.plot.position + V2(15, 75),
|
|
169
|
+
"info_interline_space" : V2(0, 24),
|
|
170
|
+
"info_font" : create_arial_font_size(24),
|
|
168
171
|
"info_precision" : 2,
|
|
169
172
|
}
|
|
170
173
|
|
|
@@ -281,10 +284,10 @@ class Plot:
|
|
|
281
284
|
pg.draw.circle(self.canvas, pointer_color, (self.size * .5)(), 15, 1) #type: ignore
|
|
282
285
|
|
|
283
286
|
if self.settings.get("show_corners_coords"):
|
|
284
|
-
self.rootEnv.print(
|
|
285
|
-
self.rootEnv.print(
|
|
286
|
-
self.rootEnv.print(
|
|
287
|
-
self.rootEnv.print(
|
|
287
|
+
self.rootEnv.print(self.top_left_plot_coord.advanced_stringify(4, True), 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)
|
|
288
|
+
self.rootEnv.print(V2(self.top_left_plot_coord.x, self.bottom_right_plot_coord.y).advanced_stringify(4, True), 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)
|
|
289
|
+
self.rootEnv.print(self.bottom_right_plot_coord.advanced_stringify(4, True), 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)
|
|
290
|
+
self.rootEnv.print(V2(self.bottom_right_plot_coord.x, self.top_left_plot_coord.y).advanced_stringify(4, True), 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)
|
|
288
291
|
|
|
289
292
|
def update(self) -> None:
|
|
290
293
|
# update mouse and center positions
|
|
@@ -389,14 +392,17 @@ class Plot:
|
|
|
389
392
|
if not render_axes_on_top: self.rootEnv.screen.blit(self.canvas, self.position())
|
|
390
393
|
|
|
391
394
|
if self.is_mouse_in_rect and self.settings.get("show_cursor_coords"):
|
|
392
|
-
self.rootEnv.print(
|
|
395
|
+
self.rootEnv.print(self.plot_mouse_position.advanced_stringify(3, True), self.rootEnv.mouse.position, fixed_sides=TEXT_FIXED_SIDES_BOTTOM_MIDDLE) #type: ignore
|
|
396
|
+
|
|
393
397
|
|
|
398
|
+
current_real_zoom = (.5**(.1*self.current_zoom)).advanced_stringify(self.settings.get('info_precision'), True, True)
|
|
394
399
|
data = [
|
|
395
400
|
[f"ZOOM:", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
|
|
396
|
-
[f" x: {
|
|
397
|
-
[f" y: {
|
|
401
|
+
[f" x: {current_real_zoom[0]};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
|
|
402
|
+
[f" y: {current_real_zoom[1]};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
|
|
403
|
+
[f" ratio: {optimize_value_string(self.current_zoom.x / self.current_zoom.y, 4)};", TEXT_FIXED_SIDES_TOP_LEFT, self.settings.get("show_zoom_info")],
|
|
398
404
|
]
|
|
399
405
|
|
|
400
406
|
for i, (d, fixed_side, show) in enumerate(data):
|
|
401
407
|
if show:
|
|
402
|
-
self.rootEnv.print(d, self.settings.get("top_left_info_position") + self.settings.get("info_interline_space") * i, fixed_sides=fixed_side)
|
|
408
|
+
self.rootEnv.print(d, self.settings.get("top_left_info_position") + self.settings.get("info_interline_space") * i, fixed_sides=fixed_side, font=self.settings.get("info_font"))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e2D
|
|
3
|
-
Version: 1.3.
|
|
3
|
+
Version: 1.3.11
|
|
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
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[metadata]
|
|
2
2
|
name = e2D
|
|
3
|
-
version = 1.3.
|
|
3
|
+
version = 1.3.11
|
|
4
4
|
author = Riccardo Mariani
|
|
5
5
|
author_email = ricomari2006@gmail.com
|
|
6
6
|
description = Python library for 2D games. Streamlines dev with keyboard/mouse input, vector calculations, color manipulation, and collision detection. Simplify game creation and unleash creativity!
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|