e2D 1.4.12__py3-none-any.whl → 1.4.13__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/__init__.py CHANGED
@@ -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
- HALF_PI = PI/2
8
- QUARTER_PI = PI/4
9
- DOUBLE_PI = PI*2
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
- # def color_lerp(current_c:list|tuple, final_c:list|tuple, step=.1) -> tuple[float, float, float]:
500
- # return tuple(c + (final_c[i] - c) * step for i,c in enumerate(current_c)) #type: ignore
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
- # def color_fade(starting_c:list|tuple, final_c:list|tuple, index, max_index) -> tuple[float, float, float]:
503
- # return tuple((starting_c[i] - final_c[i]) / max_index * (max_index - index) + final_c[i] for i in range(3)) #type: ignore
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
- # def weighted_color_fade(colors_dict:dict) -> tuple[float, float, float]:
506
- # colors = colors_dict.keys()
507
- # weights = colors_dict.values()
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
- # if float("inf") in weights: return list(colors)[list(weights).index(float("inf"))]
510
- # return tuple(sum(n[i]*w for n,w in zip(colors, weights)) / sum(weights) for i in range(3)) #type: ignore
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
- # def color_distance(starting_c:list|tuple, final_c:list|tuple, sqrd) -> float:
513
- # distance = sum([(starting_c[i]-final_c[i])**2 for i in range(3)])
514
- # return (distance ** .5) if sqrd else distance
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) % DOUBLE_PI) + DOUBLE_PI * 1.5) % DOUBLE_PI) - PI
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:
e2D/__init__.pyi CHANGED
@@ -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
- HALF_PI : float
6
- QUARTER_PI : float
7
- DOUBLE_PI : float
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
- # def color_lerp(current_c: list|tuple, final_c: list|tuple, step: int|float=.1) -> tuple[float, float, float]:
800
- # """
801
- # # Linearly interpolate between two colors.
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
- # ## Parameters:
804
- # current_c (tuple or list): The RGB values of the current color as a tuple or list.
805
- # final_c (tuple or list): The RGB values of the target color as a tuple or list.
806
- # step (int or float): The interpolation step, ranging from 0.0 (current color) to 1.0 (target color).
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
- # ## Returns:
809
- # tuple: The RGB values of the interpolated color as a tuple.
814
+ ## Returns:
815
+ tuple: The RGB values of the interpolated color as a tuple.
810
816
 
811
- # ## Example:
812
- # current_c = (255, 0, 0)
817
+ ## Example:
818
+ current_c = (255, 0, 0)
813
819
 
814
- # final_c = (0, 0, 255)
820
+ final_c = (0, 0, 255)
815
821
 
816
- # step = 0.5
822
+ step = 0.5
817
823
 
818
- # interpolated_color = color_lerp(current_c, final_c, step)
824
+ interpolated_color = color_lerp(current_c, final_c, step)
819
825
 
820
- # print(f"At step {step}: RGB {interpolated_color}")
826
+ print(f"At step {step}: RGB {interpolated_color}")
821
827
 
822
- # This will calculate the color at an interpolation step of 0.5 between (255, 0, 0) and (0, 0, 255).
823
- # """
824
- # return tuple(c + (final_c[i] - c) * step for i,c in enumerate(current_c)) #type: ignore
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
- # def color_fade(starting_c: list|tuple, final_c: list|tuple, index: int|float, max_index: int|float) -> tuple[float, float, float]:
827
- # """
828
- # # Calculate the color at a specific index of a color fade between two given colors.
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
- # ## Parameters:
831
- # starting_c (tuple or list): The RGB values of the starting color as a tuple or list.
832
- # final_c (tuple or list): The RGB values of the final color as a tuple or list.
833
- # index (int or float): The current index of the color fade, representing a position
834
- # between the starting and final colors.
835
- # max_index (int or float): The maximum index of the color fade, indicating the endpoint
836
- # position between the starting and final colors.
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
- # ## Returns:
839
- # tuple: The RGB values of the color at the specified index as a tuple.
844
+ ## Returns:
845
+ tuple: The RGB values of the color at the specified index as a tuple.
840
846
 
841
- # ## Example:
842
- # starting_c = (255, 0, 0)
847
+ ## Example:
848
+ starting_c = (255, 0, 0)
843
849
 
844
- # final_c = (0, 0, 255)
850
+ final_c = (0, 0, 255)
845
851
 
846
- # max_index = 100
852
+ max_index = 100
847
853
 
848
- # for i in range(max_index + 1):
854
+ for i in range(max_index + 1):
849
855
 
850
- # color_at_index = color_fade(starting_c, final_c, i, max_index)
856
+ color_at_index = color_fade(starting_c, final_c, i, max_index)
851
857
 
852
- # print(f"At index {i}: RGB {color_at_index}")
858
+ print(f"At index {i}: RGB {color_at_index}")
853
859
 
854
- # This will print the colors transitioning from (255, 0, 0) to (0, 0, 255).
855
- # """
856
- # return tuple((starting_c[i] - final_c[i]) / max_index * (max_index - index) + final_c[i] for i in range(3)) #type: ignore
860
+ This will print the colors transitioning from (255, 0, 0) to (0, 0, 255).
861
+ """
862
+ ...
857
863
 
858
- # def weighted_color_fade(colors_dict:dict) -> tuple[float, float, float]:
859
- # """
860
- # # Calculate the weighted color based on a dictionary of colors and their corresponding weights.
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
- # ## Parameters:
863
- # colors_dict (dict): A dictionary where keys represent RGB color values as tuples,
864
- # and values represent the weights (floats) for each color.
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
- # ## Returns:
867
- # tuple: The RGB values of the calculated weighted color as a tuple.
872
+ ## Returns:
873
+ tuple: The RGB values of the calculated weighted color as a tuple.
868
874
 
869
- # ## Example:
870
- # colors_dict = {
875
+ ## Example:
876
+ colors_dict = {
871
877
 
872
- # (255, 255, 255): 0.1,
878
+ (255, 255, 255): 0.1,
873
879
 
874
- # (0, 0, 0): 0.9,
880
+ (0, 0, 0): 0.9,
875
881
 
876
- # }
882
+ }
877
883
 
878
- # weighted_color = weighted_color_fade(colors_dict)
884
+ weighted_color = weighted_color_fade(colors_dict)
879
885
 
880
- # print(f"Weighted color: RGB {weighted_color}")
886
+ print(f"Weighted color: RGB {weighted_color}")
881
887
 
882
- # This will print the weighted color based on the provided dictionary.
883
- # """
884
- # colors = colors_dict.keys()
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
- # ## Parameters:
895
- # starting_c (list or tuple): The RGB values of the starting color.
896
- # final_c (list or tuple): The RGB values of the final color.
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
- # ## Returns:
901
- # float: The squared distance between the two colors if `sqrd` is True, otherwise
902
- # the actual distance.
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
- # ## Example:
905
- # starting_c = [255, 0, 0]
902
+ ## Returns:
903
+ float: The squared distance between the two colors if `sqrd` is True, otherwise
904
+ the actual distance.
906
905
 
907
- # final_c = [0, 255, 0]
906
+ ## Example:
907
+ starting_c = [255, 0, 0]
908
908
 
909
- # squared_distance = color_distance(starting_c, final_c)
909
+ final_c = [0, 255, 0]
910
910
 
911
- # print(f"Squared Distance: {squared_distance}")
911
+ squared_distance = color_distance(starting_c, final_c)
912
912
 
913
- # distance = color_distance(starting_c, final_c, sqrd=False)
913
+ print(f"Squared Distance: {squared_distance}")
914
914
 
915
- # print(f"Actual Distance: {distance}")
915
+ distance = color_distance(starting_c, final_c, sqrd=False)
916
916
 
917
- # This will calculate the squared and actual distances between the colors.
917
+ print(f"Actual Distance: {distance}")
918
918
 
919
- # ## Explanation:
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
- # The `sqrd` parameter allows the user to choose between returning the squared
926
- # distance or the actual distance. If `sqrd` is True, the function returns the
927
- # squared distance, and if `sqrd` is False, it returns the actual distance.
928
- # """
929
- # distance = sum([(starting_c[i]-final_c[i])**2 for i in range(3)])
930
- # return (distance ** .5) if sqrd else distance
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
  """
e2D/envs.py CHANGED
@@ -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
- window_flag : int = 0,
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__ = window_flag
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
- pg.display.update()
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.12
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
@@ -0,0 +1,12 @@
1
+ e2D/__init__.py,sha256=0bgnk4XOipVE1FAeOSwkJ85I8sXzLPEj8TnrNXGP7bw,23188
2
+ e2D/__init__.pyi,sha256=vJjIrU1F8qLyyL5OcFyW56reghTOu4qQ7xqwwYesBzA,47925
3
+ e2D/cvb.py,sha256=xMpwUBE1G2TOdah-x62W_6yXZey-n1p0OkvfiijZfNY,37445
4
+ e2D/envs.py,sha256=yh_NBLSgZFi3zwGbSzR7tZTRDn2hKzC-oQNTWQRS7VA,6292
5
+ e2D/plots.py,sha256=qNQZTwpYqDyonXGv_cDt-R3nGvu3xR7RSFDRdJma4rA,36069
6
+ e2D/utils.py,sha256=7SkfQj5Y6J3_pW9ssWMKVDSawrDANv3GtehGRVeH96k,14048
7
+ e2D/winrec.py,sha256=QMcQrED4xC8o5KAHEbhOR03lJ_-XRNAtUI3y-cRHsck,1122
8
+ e2D-1.4.13.dist-info/LICENSE,sha256=wymkNVDvj3qmjdO_rAhkRPM4t5y3_SqffGsFdgfvznU,1066
9
+ e2D-1.4.13.dist-info/METADATA,sha256=1kkNPGcb63ZzfUf-HluW5dwHCkTAcSJ_NrmLT7brPV0,9611
10
+ e2D-1.4.13.dist-info/WHEEL,sha256=a7TGlA-5DaHMRrarXjVbQagU3Man_dCnGIWMJr5kRWo,91
11
+ e2D-1.4.13.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
12
+ e2D-1.4.13.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.1.0)
2
+ Generator: setuptools (75.4.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- e2D/__init__.py,sha256=rHhqZG95FEZ8lkU8QRClAPcvgQeNqcKE_kszwCXAw3Y,22971
2
- e2D/__init__.pyi,sha256=U_mwTgruVO91O3y0CJxp9jJpO-ngcxbO9zREPo5U0xA,48495
3
- e2D/cvb.py,sha256=xMpwUBE1G2TOdah-x62W_6yXZey-n1p0OkvfiijZfNY,37445
4
- e2D/envs.py,sha256=dnve_1pmtN9P3tyXOc51yerI8GzP2pSkFsrsoKY62xk,6266
5
- e2D/plots.py,sha256=qNQZTwpYqDyonXGv_cDt-R3nGvu3xR7RSFDRdJma4rA,36069
6
- e2D/utils.py,sha256=7SkfQj5Y6J3_pW9ssWMKVDSawrDANv3GtehGRVeH96k,14048
7
- e2D/winrec.py,sha256=QMcQrED4xC8o5KAHEbhOR03lJ_-XRNAtUI3y-cRHsck,1122
8
- e2D-1.4.12.dist-info/LICENSE,sha256=wymkNVDvj3qmjdO_rAhkRPM4t5y3_SqffGsFdgfvznU,1066
9
- e2D-1.4.12.dist-info/METADATA,sha256=RPqIVVgTietngTbLEDXlPuz4Ry4eco4_0oiSvPnX13A,9611
10
- e2D-1.4.12.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
11
- e2D-1.4.12.dist-info/top_level.txt,sha256=3vKZ-CGzNlTCpzVMmM0Ht76krCofKw7hZ0wBf-dnKdM,4
12
- e2D-1.4.12.dist-info/RECORD,,
File without changes