e2D 1.4.12__tar.gz → 1.4.13__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.4.12 → e2d-1.4.13}/PKG-INFO +1 -1
- {e2d-1.4.12 → e2d-1.4.13}/e2D/__init__.py +25 -16
- {e2d-1.4.12 → e2d-1.4.13}/e2D/__init__.pyi +99 -98
- {e2d-1.4.12 → e2d-1.4.13}/e2D/envs.py +6 -5
- {e2d-1.4.12 → e2d-1.4.13}/e2D.egg-info/PKG-INFO +1 -1
- {e2d-1.4.12 → e2d-1.4.13}/setup.cfg +1 -1
- {e2d-1.4.12 → e2d-1.4.13}/LICENSE +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/README.md +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D/cvb.py +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D/plots.py +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D/utils.py +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D/winrec.py +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D.egg-info/SOURCES.txt +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D.egg-info/dependency_links.txt +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D.egg-info/requires.txt +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/e2D.egg-info/top_level.txt +0 -0
- {e2d-1.4.12 → e2d-1.4.13}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e2D
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.13
|
|
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
|
|
@@ -2,11 +2,12 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import math as _mt
|
|
4
4
|
import random as _rnd
|
|
5
|
+
from typing import Any, Generator, Literal
|
|
5
6
|
|
|
6
7
|
PI = _mt.pi
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
PI_HALF = PI/2
|
|
9
|
+
PI_QUARTER = PI/4
|
|
10
|
+
PI_DOUBLE = PI*2
|
|
10
11
|
|
|
11
12
|
sign = lambda val: -1 if val < 0 else (1 if val > 0 else 0)
|
|
12
13
|
|
|
@@ -51,6 +52,10 @@ class Vector2D:
|
|
|
51
52
|
@property
|
|
52
53
|
def length(self) -> float:
|
|
53
54
|
return (self.x ** 2 + self.y ** 2) ** .5
|
|
55
|
+
|
|
56
|
+
@property
|
|
57
|
+
def length_sqrd(self) -> float:
|
|
58
|
+
return self.x ** 2 + self.y ** 2
|
|
54
59
|
|
|
55
60
|
def floor(self, n=1) -> "Vector2D":
|
|
56
61
|
return self.__floor__(n)
|
|
@@ -356,6 +361,10 @@ class Vector2D:
|
|
|
356
361
|
else:
|
|
357
362
|
raise IndexError("V2 has only x,y...")
|
|
358
363
|
|
|
364
|
+
def __iter__(self) -> Generator[float, Any, None]:
|
|
365
|
+
yield self.x
|
|
366
|
+
yield self.y
|
|
367
|
+
|
|
359
368
|
@classmethod
|
|
360
369
|
def __normalize__(cls, other) -> "Vector2D":
|
|
361
370
|
if isinstance(other, Vector2D):
|
|
@@ -496,22 +505,22 @@ VECTORS_8_DIRECTIONS_NORM = (V2right, V2down_right_norm, V2down, V2down_left_nor
|
|
|
496
505
|
def rgb(r:float, g:float, b:float) -> tuple[float, float, float]:
|
|
497
506
|
return (r,g,b)
|
|
498
507
|
|
|
499
|
-
|
|
500
|
-
|
|
508
|
+
def color_lerp(current_c:list|tuple, final_c:list|tuple, step=.1) -> tuple[float, float, float]:
|
|
509
|
+
return tuple(c + (final_c[i] - c) * step for i,c in enumerate(current_c)) #type: ignore
|
|
501
510
|
|
|
502
|
-
|
|
503
|
-
|
|
511
|
+
def color_fade(starting_c:list|tuple, final_c:list|tuple, index, max_index) -> tuple[float, float, float]:
|
|
512
|
+
return tuple((starting_c[i] - final_c[i]) / max_index * (max_index - index) + final_c[i] for i in range(3)) #type: ignore
|
|
504
513
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
514
|
+
def weighted_color_fade(colors_dict:dict) -> tuple[float, float, float]:
|
|
515
|
+
colors = colors_dict.keys()
|
|
516
|
+
weights = colors_dict.values()
|
|
508
517
|
|
|
509
|
-
|
|
510
|
-
|
|
518
|
+
if float("inf") in weights: return list(colors)[list(weights).index(float("inf"))]
|
|
519
|
+
return tuple(sum(n[i]*w for n,w in zip(colors, weights)) / sum(weights) for i in range(3)) #type: ignore
|
|
511
520
|
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
521
|
+
def color_distance(starting_c:list|tuple, final_c:list|tuple, sqrd) -> float:
|
|
522
|
+
distance = sum([(starting_c[i]-final_c[i])**2 for i in range(3)])
|
|
523
|
+
return (distance ** .5) if sqrd else distance
|
|
515
524
|
|
|
516
525
|
def lerp(starting, ending, step=.1) -> float:
|
|
517
526
|
return starting + (ending - starting) * step
|
|
@@ -522,7 +531,7 @@ def angular_interpolation(starting_angle, final_angle, step=.1) -> float:
|
|
|
522
531
|
# return starting_angle + min((delta, delta - DOUBLE_PI, delta + DOUBLE_PI), key=abs) * step
|
|
523
532
|
|
|
524
533
|
# math way
|
|
525
|
-
shortest_angle = ((((final_angle - starting_angle) %
|
|
534
|
+
shortest_angle = ((((final_angle - starting_angle) % PI_DOUBLE) + PI_DOUBLE * 1.5) % PI_DOUBLE) - PI
|
|
526
535
|
return starting_angle + shortest_angle * step
|
|
527
536
|
|
|
528
537
|
def bezier_cubic_interpolation(t, p0, p1) -> float:
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
-
from typing import Callable, Literal
|
|
2
|
+
from typing import Any, Callable, Generator, Literal
|
|
3
3
|
|
|
4
4
|
PI : float
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
PI_HALF : float
|
|
6
|
+
PI_QUARTER : float
|
|
7
|
+
PI_DOUBLE : float
|
|
8
8
|
|
|
9
9
|
# regular expression to remove comments:
|
|
10
10
|
# """([\s\S]*?)"""
|
|
@@ -246,6 +246,10 @@ class Vector2D:
|
|
|
246
246
|
def length(self:"Vector2D") -> float:
|
|
247
247
|
...
|
|
248
248
|
|
|
249
|
+
@property
|
|
250
|
+
def length_sqrd(self:"Vector2D") -> float:
|
|
251
|
+
...
|
|
252
|
+
|
|
249
253
|
def floor(self:"Vector2D", n:"int|float|Vector2D"=1) -> "Vector2D":
|
|
250
254
|
...
|
|
251
255
|
|
|
@@ -664,7 +668,9 @@ class Vector2D:
|
|
|
664
668
|
|
|
665
669
|
def __float__(self:"Vector2D") -> "Vector2D": ...
|
|
666
670
|
|
|
667
|
-
def __getitem__(self:"Vector2D", n) -> int|float: ...
|
|
671
|
+
def __getitem__(self:"Vector2D", n:Literal[0,1,"x","y"]) -> int|float: ...
|
|
672
|
+
|
|
673
|
+
def __iter__(self:"Vector2D") -> Generator[float, Any, None]: ...
|
|
668
674
|
|
|
669
675
|
@classmethod
|
|
670
676
|
def __normalize__(cls, other:"Vector2D|int|float|tuple|list") -> "Vector2D": ...
|
|
@@ -796,138 +802,133 @@ def rgb(r:float, g:float, b:float) -> tuple[float, float, float]:
|
|
|
796
802
|
|
|
797
803
|
def lerp(starting: int|float, ending: int|float, step: int|float=.1) -> float: ...
|
|
798
804
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
#
|
|
805
|
+
def color_lerp(current_c: list|tuple, final_c: list|tuple, step: int|float=.1) -> tuple[float, float, float]:
|
|
806
|
+
"""
|
|
807
|
+
# Linearly interpolate between two colors.
|
|
802
808
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
809
|
+
## Parameters:
|
|
810
|
+
current_c (tuple or list): The RGB values of the current color as a tuple or list.
|
|
811
|
+
final_c (tuple or list): The RGB values of the target color as a tuple or list.
|
|
812
|
+
step (int or float): The interpolation step, ranging from 0.0 (current color) to 1.0 (target color).
|
|
807
813
|
|
|
808
|
-
|
|
809
|
-
|
|
814
|
+
## Returns:
|
|
815
|
+
tuple: The RGB values of the interpolated color as a tuple.
|
|
810
816
|
|
|
811
|
-
|
|
812
|
-
|
|
817
|
+
## Example:
|
|
818
|
+
current_c = (255, 0, 0)
|
|
813
819
|
|
|
814
|
-
|
|
820
|
+
final_c = (0, 0, 255)
|
|
815
821
|
|
|
816
|
-
|
|
822
|
+
step = 0.5
|
|
817
823
|
|
|
818
|
-
|
|
824
|
+
interpolated_color = color_lerp(current_c, final_c, step)
|
|
819
825
|
|
|
820
|
-
|
|
826
|
+
print(f"At step {step}: RGB {interpolated_color}")
|
|
821
827
|
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
828
|
+
This will calculate the color at an interpolation step of 0.5 between (255, 0, 0) and (0, 0, 255).
|
|
829
|
+
"""
|
|
830
|
+
...
|
|
825
831
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
#
|
|
832
|
+
def color_fade(starting_c: list|tuple, final_c: list|tuple, index: int|float, max_index: int|float) -> tuple[float, float, float]:
|
|
833
|
+
"""
|
|
834
|
+
# Calculate the color at a specific index of a color fade between two given colors.
|
|
829
835
|
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
836
|
+
## Parameters:
|
|
837
|
+
starting_c (tuple or list): The RGB values of the starting color as a tuple or list.
|
|
838
|
+
final_c (tuple or list): The RGB values of the final color as a tuple or list.
|
|
839
|
+
index (int or float): The current index of the color fade, representing a position
|
|
840
|
+
between the starting and final colors.
|
|
841
|
+
max_index (int or float): The maximum index of the color fade, indicating the endpoint
|
|
842
|
+
position between the starting and final colors.
|
|
837
843
|
|
|
838
|
-
|
|
839
|
-
|
|
844
|
+
## Returns:
|
|
845
|
+
tuple: The RGB values of the color at the specified index as a tuple.
|
|
840
846
|
|
|
841
|
-
|
|
842
|
-
|
|
847
|
+
## Example:
|
|
848
|
+
starting_c = (255, 0, 0)
|
|
843
849
|
|
|
844
|
-
|
|
850
|
+
final_c = (0, 0, 255)
|
|
845
851
|
|
|
846
|
-
|
|
852
|
+
max_index = 100
|
|
847
853
|
|
|
848
|
-
|
|
854
|
+
for i in range(max_index + 1):
|
|
849
855
|
|
|
850
|
-
|
|
856
|
+
color_at_index = color_fade(starting_c, final_c, i, max_index)
|
|
851
857
|
|
|
852
|
-
|
|
858
|
+
print(f"At index {i}: RGB {color_at_index}")
|
|
853
859
|
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
860
|
+
This will print the colors transitioning from (255, 0, 0) to (0, 0, 255).
|
|
861
|
+
"""
|
|
862
|
+
...
|
|
857
863
|
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
#
|
|
864
|
+
def weighted_color_fade(colors_dict:dict) -> tuple[float, float, float]:
|
|
865
|
+
"""
|
|
866
|
+
# Calculate the weighted color based on a dictionary of colors and their corresponding weights.
|
|
861
867
|
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
868
|
+
## Parameters:
|
|
869
|
+
colors_dict (dict): A dictionary where keys represent RGB color values as tuples,
|
|
870
|
+
and values represent the weights (floats) for each color.
|
|
865
871
|
|
|
866
|
-
|
|
867
|
-
|
|
872
|
+
## Returns:
|
|
873
|
+
tuple: The RGB values of the calculated weighted color as a tuple.
|
|
868
874
|
|
|
869
|
-
|
|
870
|
-
|
|
875
|
+
## Example:
|
|
876
|
+
colors_dict = {
|
|
871
877
|
|
|
872
|
-
|
|
878
|
+
(255, 255, 255): 0.1,
|
|
873
879
|
|
|
874
|
-
|
|
880
|
+
(0, 0, 0): 0.9,
|
|
875
881
|
|
|
876
|
-
|
|
882
|
+
}
|
|
877
883
|
|
|
878
|
-
|
|
884
|
+
weighted_color = weighted_color_fade(colors_dict)
|
|
879
885
|
|
|
880
|
-
|
|
886
|
+
print(f"Weighted color: RGB {weighted_color}")
|
|
881
887
|
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
# weights = colors_dict.values()
|
|
886
|
-
|
|
887
|
-
# if float("inf") in weights: return list(colors)[list(weights).index(float("inf"))]
|
|
888
|
-
# return tuple(sum(n[i]*w for n,w in zip(colors, weights)) / sum(weights) for i in range(3)) #type: ignore
|
|
889
|
-
|
|
890
|
-
# def color_distance(starting_c: list|tuple, final_c: list|tuple, sqrd:bool=True) -> float:
|
|
891
|
-
# """
|
|
892
|
-
# # Calculate the distance between two colors in RGB space.
|
|
888
|
+
This will print the weighted color based on the provided dictionary.
|
|
889
|
+
"""
|
|
890
|
+
...
|
|
893
891
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
#
|
|
897
|
-
# sqrd (bool, optional): If True, return the squared distance. If False, return
|
|
898
|
-
# the actual distance. Default is True.
|
|
892
|
+
def color_distance(starting_c: list|tuple, final_c: list|tuple, sqrd:bool=True) -> float:
|
|
893
|
+
"""
|
|
894
|
+
# Calculate the distance between two colors in RGB space.
|
|
899
895
|
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
896
|
+
## Parameters:
|
|
897
|
+
starting_c (list or tuple): The RGB values of the starting color.
|
|
898
|
+
final_c (list or tuple): The RGB values of the final color.
|
|
899
|
+
sqrd (bool, optional): If True, return the squared distance. If False, return
|
|
900
|
+
the actual distance. Default is True.
|
|
903
901
|
|
|
904
|
-
|
|
905
|
-
|
|
902
|
+
## Returns:
|
|
903
|
+
float: The squared distance between the two colors if `sqrd` is True, otherwise
|
|
904
|
+
the actual distance.
|
|
906
905
|
|
|
907
|
-
|
|
906
|
+
## Example:
|
|
907
|
+
starting_c = [255, 0, 0]
|
|
908
908
|
|
|
909
|
-
|
|
909
|
+
final_c = [0, 255, 0]
|
|
910
910
|
|
|
911
|
-
|
|
911
|
+
squared_distance = color_distance(starting_c, final_c)
|
|
912
912
|
|
|
913
|
-
|
|
913
|
+
print(f"Squared Distance: {squared_distance}")
|
|
914
914
|
|
|
915
|
-
|
|
915
|
+
distance = color_distance(starting_c, final_c, sqrd=False)
|
|
916
916
|
|
|
917
|
-
|
|
917
|
+
print(f"Actual Distance: {distance}")
|
|
918
918
|
|
|
919
|
-
|
|
920
|
-
# The function first calculates the squared distance between the two colors in RGB
|
|
921
|
-
# space. It does this by computing the sum of the squared differences of the RGB
|
|
922
|
-
# components for each color. The squared distance is obtained by taking the square
|
|
923
|
-
# root of this sum.
|
|
919
|
+
This will calculate the squared and actual distances between the colors.
|
|
924
920
|
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
921
|
+
## Explanation:
|
|
922
|
+
The function first calculates the squared distance between the two colors in RGB
|
|
923
|
+
space. It does this by computing the sum of the squared differences of the RGB
|
|
924
|
+
components for each color. The squared distance is obtained by taking the square
|
|
925
|
+
root of this sum.
|
|
926
|
+
|
|
927
|
+
The `sqrd` parameter allows the user to choose between returning the squared
|
|
928
|
+
distance or the actual distance. If `sqrd` is True, the function returns the
|
|
929
|
+
squared distance, and if `sqrd` is False, it returns the actual distance.
|
|
930
|
+
"""
|
|
931
|
+
...
|
|
931
932
|
|
|
932
933
|
def angular_interpolation(starting_angle: int|float, final_angle: int|float, step: int|float=.1) -> float:
|
|
933
934
|
"""
|
|
@@ -41,13 +41,13 @@ class RootEnv:
|
|
|
41
41
|
show_fps = True,
|
|
42
42
|
quit_on_key_pressed : None|int = pg.K_x,
|
|
43
43
|
vsync : bool = True,
|
|
44
|
-
|
|
44
|
+
window_flags : int = pg.DOUBLEBUF,
|
|
45
45
|
clear_screen_each_frame : bool = True) -> None:
|
|
46
46
|
self.quit = False
|
|
47
47
|
self.__screen_size__ :Vector2D= screen_size
|
|
48
48
|
|
|
49
49
|
self.__vsync__ = vsync
|
|
50
|
-
self.__flags__ =
|
|
50
|
+
self.__flags__ = window_flags
|
|
51
51
|
self.screen = pg.display.set_mode(self.__screen_size__(), vsync=self.__vsync__, flags=self.__flags__)
|
|
52
52
|
|
|
53
53
|
self.clock = pg.time.Clock()
|
|
@@ -108,7 +108,7 @@ class RootEnv:
|
|
|
108
108
|
|
|
109
109
|
@property
|
|
110
110
|
def runtime_seconds(self) -> float:
|
|
111
|
-
return pg.time.get_ticks()
|
|
111
|
+
return pg.time.get_ticks() / 1e3
|
|
112
112
|
|
|
113
113
|
def init(self, sub_env:DefEnv) -> None:
|
|
114
114
|
self.env = sub_env
|
|
@@ -147,11 +147,12 @@ class RootEnv:
|
|
|
147
147
|
self.clock.tick(self.target_fps)
|
|
148
148
|
self.current_fps = self.clock.get_fps()
|
|
149
149
|
if self.clear_screen_each_frame: self.clear()
|
|
150
|
-
if self.show_fps: self.print(str(round(self.current_fps,2)), self.screen_size * .01, bg_color=(0,0,0))
|
|
151
150
|
|
|
152
151
|
self.env.draw()
|
|
153
152
|
for util in self.utils.values(): util.draw()
|
|
154
|
-
|
|
153
|
+
|
|
154
|
+
if self.show_fps: self.print(str(round(self.current_fps,2)), self.screen_size * .01, bg_color=(0,0,0))
|
|
155
|
+
pg.display.flip()
|
|
155
156
|
|
|
156
157
|
def __update__(self) -> None:
|
|
157
158
|
self.mouse.update()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: e2D
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.13
|
|
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.4.
|
|
3
|
+
version = 1.4.13
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|