e2D 1.4.16__tar.gz → 1.4.18__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.16 → e2d-1.4.18}/PKG-INFO +1 -1
- {e2d-1.4.16 → e2d-1.4.18}/e2D/__init__.py +5 -22
- {e2d-1.4.16 → e2d-1.4.18}/e2D/__init__.pyi +5 -133
- {e2d-1.4.16 → e2d-1.4.18}/e2D/colors.py +106 -129
- e2d-1.4.18/e2D/def_colors.py +1732 -0
- {e2d-1.4.16 → e2d-1.4.18}/e2D/envs.py +9 -9
- {e2d-1.4.16 → e2d-1.4.18}/e2D/plots.py +25 -25
- {e2d-1.4.16 → e2d-1.4.18}/e2D.egg-info/PKG-INFO +1 -1
- {e2d-1.4.16 → e2d-1.4.18}/e2D.egg-info/SOURCES.txt +1 -0
- {e2d-1.4.16 → e2d-1.4.18}/setup.cfg +1 -1
- {e2d-1.4.16 → e2d-1.4.18}/LICENSE +0 -0
- {e2d-1.4.16 → e2d-1.4.18}/README.md +0 -0
- {e2d-1.4.16 → e2d-1.4.18}/e2D/utils.py +0 -0
- {e2d-1.4.16 → e2d-1.4.18}/e2D/winrec.py +0 -0
- {e2d-1.4.16 → e2d-1.4.18}/e2D.egg-info/dependency_links.txt +0 -0
- {e2d-1.4.16 → e2d-1.4.18}/e2D.egg-info/requires.txt +0 -0
- {e2d-1.4.16 → e2d-1.4.18}/e2D.egg-info/top_level.txt +0 -0
- {e2d-1.4.16 → e2d-1.4.18}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: e2D
|
|
3
|
-
Version: 1.4.
|
|
3
|
+
Version: 1.4.18
|
|
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
|
|
@@ -17,7 +17,7 @@ class Vector2D:
|
|
|
17
17
|
self.x = x
|
|
18
18
|
self.y = y
|
|
19
19
|
|
|
20
|
-
def distance_to(self, other, rooted=True) ->
|
|
20
|
+
def distance_to(self, other, rooted=True) -> float:
|
|
21
21
|
d = (self.x - other.x)**2 + (self.y - other.y)**2
|
|
22
22
|
return d**(1/2) if rooted else d
|
|
23
23
|
|
|
@@ -56,6 +56,10 @@ class Vector2D:
|
|
|
56
56
|
@property
|
|
57
57
|
def length_sqrd(self) -> float:
|
|
58
58
|
return self.x ** 2 + self.y ** 2
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def inverse(self) -> "Vector2D":
|
|
62
|
+
return self.mult(-1)
|
|
59
63
|
|
|
60
64
|
def floor(self, n=1) -> "Vector2D":
|
|
61
65
|
return self.__floor__(n)
|
|
@@ -494,27 +498,6 @@ VECTORS_4_SEMIDIRECTIONS_NORM = (V2down_right_norm, V2down_left_norm, V2up_left_
|
|
|
494
498
|
VECTORS_8_DIRECTIONS = (V2right, V2down_right, V2down, V2down_left, V2left, V2up_left, V2up, V2up_right)
|
|
495
499
|
VECTORS_8_DIRECTIONS_NORM = (V2right, V2down_right_norm, V2down, V2down_left_norm, V2left, V2up_left_norm, V2up, V2up_right_norm)
|
|
496
500
|
|
|
497
|
-
|
|
498
|
-
def rgb(r:float, g:float, b:float) -> tuple[float, float, float]:
|
|
499
|
-
return (r,g,b)
|
|
500
|
-
|
|
501
|
-
def color_lerp(current_c:list|tuple, final_c:list|tuple, step=.1) -> tuple[float, float, float]:
|
|
502
|
-
return tuple(c + (final_c[i] - c) * step for i,c in enumerate(current_c)) #type: ignore
|
|
503
|
-
|
|
504
|
-
def color_fade(starting_c:list|tuple, final_c:list|tuple, index, max_index) -> tuple[float, float, float]:
|
|
505
|
-
return tuple((starting_c[i] - final_c[i]) / max_index * (max_index - index) + final_c[i] for i in range(3)) #type: ignore
|
|
506
|
-
|
|
507
|
-
def weighted_color_fade(colors_dict:dict) -> tuple[float, float, float]:
|
|
508
|
-
colors = colors_dict.keys()
|
|
509
|
-
weights = colors_dict.values()
|
|
510
|
-
|
|
511
|
-
if float("inf") in weights: return list(colors)[list(weights).index(float("inf"))]
|
|
512
|
-
return tuple(sum(n[i]*w for n,w in zip(colors, weights)) / sum(weights) for i in range(3)) #type: ignore
|
|
513
|
-
|
|
514
|
-
def color_distance(starting_c:list|tuple, final_c:list|tuple, rooted) -> float:
|
|
515
|
-
distance = sum([(starting_c[i]-final_c[i])**2 for i in range(3)])
|
|
516
|
-
return (distance ** .5) if rooted else distance
|
|
517
|
-
|
|
518
501
|
def lerp(starting, ending, step=.1) -> float:
|
|
519
502
|
return starting + (ending - starting) * step
|
|
520
503
|
|
|
@@ -39,7 +39,7 @@ class Vector2D:
|
|
|
39
39
|
self.x : int|float
|
|
40
40
|
self.y : int|float
|
|
41
41
|
|
|
42
|
-
def distance_to(self:"Vector2D", other:"Vector2D", rooted:bool=True) ->
|
|
42
|
+
def distance_to(self:"Vector2D", other:"Vector2D", rooted:bool=True) -> float:
|
|
43
43
|
"""
|
|
44
44
|
# Calculate the distance between the current Vector2D other and another other.
|
|
45
45
|
|
|
@@ -249,6 +249,10 @@ class Vector2D:
|
|
|
249
249
|
@property
|
|
250
250
|
def length_sqrd(self:"Vector2D") -> float:
|
|
251
251
|
...
|
|
252
|
+
|
|
253
|
+
@property
|
|
254
|
+
def inverse(self:"Vector2D") -> "Vector2D":
|
|
255
|
+
...
|
|
252
256
|
|
|
253
257
|
def floor(self:"Vector2D", n:"int|float|Vector2D"=1) -> "Vector2D":
|
|
254
258
|
...
|
|
@@ -796,140 +800,8 @@ VECTORS_4_SEMIDIRECTIONS_NORM : tuple[Vector2D, Vector2D, Vector2D, Vector2D,]
|
|
|
796
800
|
VECTORS_8_DIRECTIONS : tuple[Vector2D, Vector2D, Vector2D, Vector2D, Vector2D, Vector2D, Vector2D, Vector2D]
|
|
797
801
|
VECTORS_8_DIRECTIONS_NORM : tuple[Vector2D, Vector2D, Vector2D, Vector2D, Vector2D, Vector2D, Vector2D, Vector2D]
|
|
798
802
|
|
|
799
|
-
|
|
800
|
-
def rgb(r:float, g:float, b:float) -> tuple[float, float, float]:
|
|
801
|
-
return (r,g,b)
|
|
802
|
-
|
|
803
803
|
def lerp(starting: int|float, ending: int|float, step: int|float=.1) -> float: ...
|
|
804
804
|
|
|
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.
|
|
808
|
-
|
|
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).
|
|
813
|
-
|
|
814
|
-
## Returns:
|
|
815
|
-
tuple: The RGB values of the interpolated color as a tuple.
|
|
816
|
-
|
|
817
|
-
## Example:
|
|
818
|
-
current_c = (255, 0, 0)
|
|
819
|
-
|
|
820
|
-
final_c = (0, 0, 255)
|
|
821
|
-
|
|
822
|
-
step = 0.5
|
|
823
|
-
|
|
824
|
-
interpolated_color = color_lerp(current_c, final_c, step)
|
|
825
|
-
|
|
826
|
-
print(f"At step {step}: RGB {interpolated_color}")
|
|
827
|
-
|
|
828
|
-
This will calculate the color at an interpolation step of 0.5 between (255, 0, 0) and (0, 0, 255).
|
|
829
|
-
"""
|
|
830
|
-
...
|
|
831
|
-
|
|
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.
|
|
835
|
-
|
|
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.
|
|
843
|
-
|
|
844
|
-
## Returns:
|
|
845
|
-
tuple: The RGB values of the color at the specified index as a tuple.
|
|
846
|
-
|
|
847
|
-
## Example:
|
|
848
|
-
starting_c = (255, 0, 0)
|
|
849
|
-
|
|
850
|
-
final_c = (0, 0, 255)
|
|
851
|
-
|
|
852
|
-
max_index = 100
|
|
853
|
-
|
|
854
|
-
for i in range(max_index + 1):
|
|
855
|
-
|
|
856
|
-
color_at_index = color_fade(starting_c, final_c, i, max_index)
|
|
857
|
-
|
|
858
|
-
print(f"At index {i}: RGB {color_at_index}")
|
|
859
|
-
|
|
860
|
-
This will print the colors transitioning from (255, 0, 0) to (0, 0, 255).
|
|
861
|
-
"""
|
|
862
|
-
...
|
|
863
|
-
|
|
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.
|
|
867
|
-
|
|
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.
|
|
871
|
-
|
|
872
|
-
## Returns:
|
|
873
|
-
tuple: The RGB values of the calculated weighted color as a tuple.
|
|
874
|
-
|
|
875
|
-
## Example:
|
|
876
|
-
colors_dict = {
|
|
877
|
-
|
|
878
|
-
(255, 255, 255): 0.1,
|
|
879
|
-
|
|
880
|
-
(0, 0, 0): 0.9,
|
|
881
|
-
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
weighted_color = weighted_color_fade(colors_dict)
|
|
885
|
-
|
|
886
|
-
print(f"Weighted color: RGB {weighted_color}")
|
|
887
|
-
|
|
888
|
-
This will print the weighted color based on the provided dictionary.
|
|
889
|
-
"""
|
|
890
|
-
...
|
|
891
|
-
|
|
892
|
-
def color_distance(starting_c: list|tuple, final_c: list|tuple, rooted:bool=True) -> float:
|
|
893
|
-
"""
|
|
894
|
-
# Calculate the distance between two colors in RGB space.
|
|
895
|
-
|
|
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
|
-
rooted (bool, optional): If True, return the rooted distance. If False, return
|
|
900
|
-
the actual distance. Default is True.
|
|
901
|
-
|
|
902
|
-
## Returns:
|
|
903
|
-
float: The squared distance between the two colors if `rooted` is False, otherwise
|
|
904
|
-
the actual distance.
|
|
905
|
-
|
|
906
|
-
## Example:
|
|
907
|
-
starting_c = [255, 0, 0]
|
|
908
|
-
|
|
909
|
-
final_c = [0, 255, 0]
|
|
910
|
-
|
|
911
|
-
squared_distance = color_distance(starting_c, final_c)
|
|
912
|
-
|
|
913
|
-
print(f"Squared Distance: {squared_distance}")
|
|
914
|
-
|
|
915
|
-
distance = color_distance(starting_c, final_c, rooted=True)
|
|
916
|
-
|
|
917
|
-
print(f"Actual Distance: {distance}")
|
|
918
|
-
|
|
919
|
-
This will calculate the squared and actual distances between the colors.
|
|
920
|
-
|
|
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 `rooted` parameter allows the user to choose between returning the squared
|
|
928
|
-
distance or the actual distance. If `rooted` is True, the function returns the
|
|
929
|
-
actual distance, and if `rooted` is False, it returns the squared distance.
|
|
930
|
-
"""
|
|
931
|
-
...
|
|
932
|
-
|
|
933
805
|
def angular_interpolation(starting_angle: int|float, final_angle: int|float, step: int|float=.1) -> float:
|
|
934
806
|
"""
|
|
935
807
|
# Perform angular interpolation between two angles using the shortest distance.
|
|
@@ -86,6 +86,22 @@ class Color:
|
|
|
86
86
|
def __init__(self, *values, mode:__LITERAL_COLOR_MODES__=RGB_COLOR_MODE) -> None:
|
|
87
87
|
self.__dict__ = dict(zip(mode, values))
|
|
88
88
|
self.mode :__LITERAL_COLOR_MODES__= mode
|
|
89
|
+
|
|
90
|
+
def lerp(self, other:"Color", step=.1) -> "Color":
|
|
91
|
+
return (self + (other - self).mult(step))
|
|
92
|
+
|
|
93
|
+
@staticmethod
|
|
94
|
+
def weighted_lerp(colors_dict:dict["Color", float]) -> "Color":
|
|
95
|
+
"""Colors HAVE to be in the rgb format."""
|
|
96
|
+
|
|
97
|
+
colors = colors_dict.keys()
|
|
98
|
+
weights = colors_dict.values()
|
|
99
|
+
if float("inf") in weights: return list(colors)[list(weights).index(float("inf"))]
|
|
100
|
+
return sum(n.mult(w) for n,w in zip(colors, weights)).div(sum(weights))
|
|
101
|
+
|
|
102
|
+
def distance_to(self, other:"Color", rooted=True) -> float:
|
|
103
|
+
d = sum((self.to_rgb() - other.to_rgb()).pow(2))
|
|
104
|
+
return (d ** .5) if rooted else d
|
|
89
105
|
|
|
90
106
|
@classmethod
|
|
91
107
|
def new_rgb(cls, r:int|float, g:int|float, b:int|float) -> "Color":
|
|
@@ -163,134 +179,107 @@ class Color:
|
|
|
163
179
|
return "Color(" + ", ".join(f"{k}:{v}" for k, v in self.items) + ")"
|
|
164
180
|
|
|
165
181
|
def __call__(self) -> __color_pygame__:
|
|
166
|
-
return __color_pygame__(
|
|
182
|
+
return __color_pygame__(int(self.r), int(self.g), int(self.b))
|
|
167
183
|
|
|
168
184
|
# fast operations Vector2D.operation(both,x,y)
|
|
169
185
|
def add(self, all3=.0, r=.0, g=.0, b=.0) -> "Color":
|
|
170
|
-
|
|
171
|
-
return Color(c_color.r + (r + all3), c_color.g + (g + all3), c_color.b + (b + all3)).to_mode(self.mode) # type: ignore
|
|
186
|
+
return Color(self.r + (r + all3), self.g + (g + all3), self.b + (b + all3))
|
|
172
187
|
|
|
173
188
|
def sub(self, all3=.0, r=.0, g=.0, b=.0) -> "Color":
|
|
174
|
-
|
|
175
|
-
return Color(c_color.r - (r + all3), c_color.g - (g + all3), c_color.b - (b + all3)).to_mode(self.mode) # type: ignore
|
|
189
|
+
return Color(self.r - (r + all3), self.g - (g + all3), self.b - (b + all3))
|
|
176
190
|
|
|
177
191
|
def mult(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
178
|
-
|
|
179
|
-
return Color(c_color.r * r * all3, c_color.g * g * all3, c_color.b * b * all3).to_mode(self.mode) # type: ignore
|
|
192
|
+
return Color(self.r * r * all3, self.g * g * all3, self.b * b * all3)
|
|
180
193
|
|
|
181
194
|
def pow(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
182
|
-
|
|
183
|
-
return Color(c_color.r ** (r + all3), c_color.g ** (g + all3), c_color.b ** (b + all3)).to_mode(self.mode) # type: ignore
|
|
195
|
+
return Color(self.r ** (r + all3), self.g ** (g + all3), self.b ** (b + all3))
|
|
184
196
|
|
|
185
197
|
def mod(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
186
|
-
|
|
187
|
-
return Color(c_color.r % (r + all3), c_color.g % (g + all3), c_color.b % (b + all3)).to_mode(self.mode) # type: ignore
|
|
198
|
+
return Color(self.r % (r + all3), self.g % (g + all3), self.b % (b + all3))
|
|
188
199
|
|
|
189
200
|
def div(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
190
|
-
|
|
191
|
-
return Color(c_color.r / r / all3, c_color.g / g / all3, c_color.b / b / all3).to_mode(self.mode) # type: ignore
|
|
201
|
+
return Color(self.r / r / all3, self.g / g / all3, self.b / b / all3)
|
|
192
202
|
|
|
193
203
|
def fdiv(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
194
|
-
|
|
195
|
-
return Color(c_color.r // r // all3, c_color.g // g // all3, c_color.b // b // all3).to_mode(self.mode) # type: ignore
|
|
204
|
+
return Color(self.r // r // all3, self.g // g // all3, self.b // b // all3)
|
|
196
205
|
|
|
197
206
|
# fast inplace operations Vector2D.ioperation(both,x,y)
|
|
198
|
-
def set(self,
|
|
199
|
-
self.
|
|
200
|
-
self.
|
|
207
|
+
def set(self, all3=.0, r=.0, g=.0, b=.0) -> "Color":
|
|
208
|
+
self.r = r + all3
|
|
209
|
+
self.g = g + all3
|
|
210
|
+
self.b = b + all3
|
|
201
211
|
return self
|
|
202
212
|
|
|
203
213
|
def iadd(self, all3=.0, r=.0, g=.0, b=.0) -> "Color":
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
c_color.b += b + all3 # type: ignore
|
|
208
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
214
|
+
self.r += r + all3
|
|
215
|
+
self.g += g + all3
|
|
216
|
+
self.b += b + all3
|
|
209
217
|
return self
|
|
210
218
|
|
|
211
219
|
def isub(self, all3=.0, r=.0, g=.0, b=.0) -> "Color":
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
c_color.b -= b + all3 # type: ignore
|
|
216
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
220
|
+
self.r -= r + all3
|
|
221
|
+
self.g -= g + all3
|
|
222
|
+
self.b -= b + all3
|
|
217
223
|
return self
|
|
218
224
|
|
|
219
225
|
def imult(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
c_color.b *= b * all3 # type: ignore
|
|
224
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
226
|
+
self.r *= r * all3
|
|
227
|
+
self.g *= g * all3
|
|
228
|
+
self.b *= b * all3
|
|
225
229
|
return self
|
|
226
230
|
|
|
227
231
|
def ipow(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
c_color.b **= b + all3 # type: ignore
|
|
232
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
232
|
+
self.r **= r + all3
|
|
233
|
+
self.g **= g + all3
|
|
234
|
+
self.b **= b + all3
|
|
233
235
|
return self
|
|
234
236
|
|
|
235
237
|
def imod(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
c_color.b %= b + all3 # type: ignore
|
|
240
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
238
|
+
self.r %= r + all3
|
|
239
|
+
self.g %= g + all3
|
|
240
|
+
self.b %= b + all3
|
|
241
241
|
return self
|
|
242
242
|
|
|
243
243
|
def idiv(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
c_color.b /= b * all3 # type: ignore
|
|
248
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
244
|
+
self.r /= r * all3
|
|
245
|
+
self.g /= g * all3
|
|
246
|
+
self.b /= b * all3
|
|
249
247
|
return self
|
|
250
248
|
|
|
251
249
|
def ifdiv(self, all3=1.0, r=1.0, g=1.0, b=1.0) -> "Color":
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
c_color.b //= b * all3 # type: ignore
|
|
256
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
250
|
+
self.r //= r * all3
|
|
251
|
+
self.g //= g * all3
|
|
252
|
+
self.b //= b * all3
|
|
257
253
|
return self
|
|
258
254
|
|
|
259
255
|
# normal operations Vector2D + a
|
|
260
256
|
def __add__(self, other) -> "Color":
|
|
261
257
|
other = Color.__normalize__(other)
|
|
262
|
-
|
|
263
|
-
return Color(c_color.r + other.r, c_color.g + other.g, c_color.b + other.b).to_mode(self.mode) # type: ignore
|
|
258
|
+
return Color(self.r + other.r, self.g + other.g, self.b + other.b)
|
|
264
259
|
|
|
265
260
|
def __sub__(self, other) -> "Color":
|
|
266
261
|
other = Color.__normalize__(other)
|
|
267
|
-
|
|
268
|
-
return Color(c_color.r - other.r, c_color.g - other.g, c_color.b - other.b).to_mode(self.mode) # type: ignore
|
|
262
|
+
return Color(self.r - other.r, self.g - other.g, self.b - other.b)
|
|
269
263
|
|
|
270
264
|
def __mul__(self, other) -> "Color":
|
|
271
265
|
other = Color.__normalize__(other)
|
|
272
|
-
|
|
273
|
-
return Color(c_color.r * other.r, c_color.g * other.g, c_color.b * other.b).to_mode(self.mode) # type: ignore
|
|
266
|
+
return Color(self.r * other.r, self.g * other.g, self.b * other.b)
|
|
274
267
|
|
|
275
268
|
def __mod__(self, other) -> "Color":
|
|
276
269
|
other = Color.__normalize__(other)
|
|
277
|
-
|
|
278
|
-
return Color(c_color.r % other.r, c_color.g % other.g, c_color.b % other.b).to_mode(self.mode) # type: ignore
|
|
270
|
+
return Color(self.r % other.r, self.g % other.g, self.b % other.b)
|
|
279
271
|
|
|
280
272
|
def __pow__(self, other) -> "Color":
|
|
281
273
|
other = Color.__normalize__(other)
|
|
282
|
-
|
|
283
|
-
return Color(c_color.r ** other.r, c_color.g ** other.g, c_color.b ** other.b).to_mode(self.mode) # type: ignore
|
|
274
|
+
return Color(self.r ** other.r, self.g ** other.g, self.b ** other.b)
|
|
284
275
|
|
|
285
276
|
def __truediv__(self, other) -> "Color":
|
|
286
277
|
other = Color.__normalize__(other)
|
|
287
|
-
|
|
288
|
-
return Color(c_color.r / other.r, c_color.g / other.g, c_color.b / other.b).to_mode(self.mode) # type: ignore
|
|
278
|
+
return Color(self.r / other.r, self.g / other.g, self.b / other.b)
|
|
289
279
|
|
|
290
280
|
def __floordiv__(self, other) -> "Color":
|
|
291
281
|
other = Color.__normalize__(other)
|
|
292
|
-
|
|
293
|
-
return Color(c_color.r // other.r, c_color.g // other.g, c_color.b // other.b).to_mode(self.mode) # type: ignore
|
|
282
|
+
return Color(self.r // other.r, self.g // other.g, self.b // other.b)
|
|
294
283
|
|
|
295
284
|
# right operations a + Vector2D
|
|
296
285
|
def __radd__(self, other) -> "Color":
|
|
@@ -298,128 +287,104 @@ class Color:
|
|
|
298
287
|
|
|
299
288
|
def __rsub__(self, other) -> "Color":
|
|
300
289
|
other = Color.__normalize__(other)
|
|
301
|
-
|
|
302
|
-
return Color(other.r - c_color.r, other.g - c_color.g, other.b - c_color.b).to_mode(self.mode) # type: ignore
|
|
290
|
+
return Color(other.r - self.r, other.g - self.g, other.b - self.b)
|
|
303
291
|
|
|
304
292
|
def __rmul__(self, other) -> "Color":
|
|
305
293
|
return self.__mul__(other)
|
|
306
294
|
|
|
307
295
|
def __rmod__(self, other) -> "Color":
|
|
308
296
|
other = Color.__normalize__(other)
|
|
309
|
-
|
|
310
|
-
return Color(other.r % c_color.r, other.g % c_color.g, other.b % c_color.b).to_mode(self.mode) # type: ignore
|
|
297
|
+
return Color(other.r % self.r, other.g % self.g, other.b % self.b)
|
|
311
298
|
|
|
312
299
|
def __rpow__(self, other) -> "Color":
|
|
313
300
|
other = Color.__normalize__(other)
|
|
314
|
-
|
|
315
|
-
return Color(other.r ** c_color.r, other.g ** c_color.g, other.b ** c_color.b).to_mode(self.mode) # type: ignore
|
|
301
|
+
return Color(other.r ** self.r, other.g ** self.g, other.b ** self.b)
|
|
316
302
|
|
|
317
303
|
def __rtruediv__(self, other) -> "Color":
|
|
318
304
|
other = Color.__normalize__(other)
|
|
319
|
-
|
|
320
|
-
return Color(other.r / c_color.r, other.g / c_color.g, other.b / c_color.b).to_mode(self.mode) # type: ignore
|
|
305
|
+
return Color(other.r / self.r, other.g / self.g, other.b / self.b)
|
|
321
306
|
|
|
322
307
|
def __rfloordiv__(self, other) -> "Color":
|
|
323
308
|
other = Color.__normalize__(other)
|
|
324
|
-
|
|
325
|
-
return Color(other.r // c_color.r, other.g // c_color.g, other.b // c_color.b).to_mode(self.mode) # type: ignore
|
|
309
|
+
return Color(other.r // self.r, other.g // self.g, other.b // self.b)
|
|
326
310
|
|
|
327
311
|
# in-place operations Vector2D += a
|
|
328
312
|
def __iadd__(self, other) -> "Color":
|
|
329
313
|
other = Color.__normalize__(other)
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
c_color.b += other.b # type: ignore
|
|
334
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
314
|
+
self.r += other.r
|
|
315
|
+
self.g += other.g
|
|
316
|
+
self.b += other.b
|
|
335
317
|
return self
|
|
336
318
|
|
|
337
319
|
def __isub__(self, other) -> "Color":
|
|
338
320
|
other = Color.__normalize__(other)
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
c_color.b -= other.b # type: ignore
|
|
343
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
321
|
+
self.r -= other.r
|
|
322
|
+
self.g -= other.g
|
|
323
|
+
self.b -= other.b
|
|
344
324
|
return self
|
|
345
325
|
|
|
346
326
|
def __imul__(self, other) -> "Color":
|
|
347
327
|
other = Color.__normalize__(other)
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
c_color.b *= other.b # type: ignore
|
|
352
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
328
|
+
self.r *= other.r
|
|
329
|
+
self.g *= other.g
|
|
330
|
+
self.b *= other.b
|
|
353
331
|
return self
|
|
354
332
|
|
|
355
333
|
def __itruediv__(self, other) -> "Color":
|
|
356
334
|
other = Color.__normalize__(other)
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
c_color.b **= other.b # type: ignore
|
|
361
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
335
|
+
self.r **= other.r
|
|
336
|
+
self.g **= other.g
|
|
337
|
+
self.b **= other.b
|
|
362
338
|
return self
|
|
363
339
|
|
|
364
340
|
def __imod__(self, other) -> "Color":
|
|
365
341
|
other = Color.__normalize__(other)
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
c_color.b %= other.b # type: ignore
|
|
370
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
342
|
+
self.r %= other.r
|
|
343
|
+
self.g %= other.g
|
|
344
|
+
self.b %= other.b
|
|
371
345
|
return self
|
|
372
346
|
|
|
373
347
|
def __ipow__(self, other) -> "Color":
|
|
374
348
|
other = Color.__normalize__(other)
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
c_color.b /= other.b # type: ignore
|
|
379
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
349
|
+
self.r /= other.r
|
|
350
|
+
self.g /= other.g
|
|
351
|
+
self.b /= other.b
|
|
380
352
|
return self
|
|
381
353
|
|
|
382
354
|
def __ifloordiv__(self, other) -> "Color":
|
|
383
355
|
other = Color.__normalize__(other)
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
c_color.b //= other.b # type: ignore
|
|
388
|
-
self.__dict__ = c_color.to_mode(self.mode).__dict__
|
|
356
|
+
self.r //= other.r
|
|
357
|
+
self.g //= other.g
|
|
358
|
+
self.b //= other.b
|
|
389
359
|
return self
|
|
390
360
|
|
|
391
361
|
# comparasion
|
|
392
362
|
def __eq__(self, other) -> bool:
|
|
393
363
|
try: other = Color.__normalize__(other)
|
|
394
364
|
except: return False
|
|
395
|
-
|
|
396
|
-
return c_color.r == other.r and c_color.g == other.g and c_color.b == other.b # type: ignore
|
|
365
|
+
return self.r == other.r and self.g == other.g and self.b == other.b
|
|
397
366
|
|
|
398
367
|
def __ne__(self, other) -> bool:
|
|
399
368
|
return not self.__eq__(other)
|
|
400
369
|
|
|
401
370
|
def __abs__(self) -> "Color":
|
|
402
|
-
|
|
403
|
-
return Color(abs(
|
|
371
|
+
self = self.to_rgb()
|
|
372
|
+
return Color(abs(self.r), abs(self.g), abs(self.b))
|
|
404
373
|
|
|
405
374
|
def __round__(self, n=1) -> "Color":
|
|
406
375
|
n = Color.__normalize__(n)
|
|
407
|
-
|
|
408
|
-
return Color(round(c_color.r / n.r) * n.r, round(c_color.g / n.g) * n.g, round(c_color.b / n.b) * n.b).to_mode(self.mode) # type: ignore
|
|
376
|
+
return Color(round(self.r / n.r) * n.r, round(self.g / n.g) * n.g, round(self.b / n.b) * n.b)
|
|
409
377
|
|
|
410
378
|
def __floor__(self, n=1) -> "Color":
|
|
411
379
|
n = Color.__normalize__(n)
|
|
412
|
-
|
|
413
|
-
return Color((c_color.r / n.r).__floor__() * n.r, (c_color.g / n.g).__floor__() * n.g, (c_color.b / n.b).__floor__() * n.b).to_mode(self.mode) # type: ignore
|
|
380
|
+
return Color((self.r / n.r).__floor__() * n.r, (self.g / n.g).__floor__() * n.g, (self.b / n.b).__floor__() * n.b)
|
|
414
381
|
|
|
415
382
|
def __ceil__(self, n=1) -> "Color":
|
|
416
383
|
n = Color.__normalize__(n)
|
|
417
|
-
|
|
418
|
-
return Color((c_color.r / n.r).__ceil__() * n.r, (c_color.g / n.g).__ceil__() * n.g, (c_color.b / n.b).__ceil__() * n.b).to_mode(self.mode) # type: ignore
|
|
384
|
+
return Color((self.r / n.r).__ceil__() * n.r, (self.g / n.g).__ceil__() * n.g, (self.b / n.b).__ceil__() * n.b)
|
|
419
385
|
|
|
420
386
|
def __float__(self) -> "Color":
|
|
421
|
-
|
|
422
|
-
return Color(float(c_color.r), float(c_color.g), float(c_color.b)).to_mode(self.mode) # type: ignore
|
|
387
|
+
return Color(float(self.r), float(self.g), float(self.b))
|
|
423
388
|
|
|
424
389
|
def __getitem__(self, n) -> int|float:
|
|
425
390
|
return self.values[n] if isinstance(n, int) else self.values[self.keys.index(n)]
|
|
@@ -432,6 +397,8 @@ class Color:
|
|
|
432
397
|
def __normalize__(cls, other) -> "Color":
|
|
433
398
|
if isinstance(other, Color):
|
|
434
399
|
return other
|
|
400
|
+
if isinstance(other, __color_pygame__):
|
|
401
|
+
return cls(*other[:], mode="rgba")
|
|
435
402
|
if isinstance(other, (int, float)):
|
|
436
403
|
return cls(other, other, other)
|
|
437
404
|
if isinstance(other, (list, tuple)):
|
|
@@ -451,13 +418,23 @@ class Color:
|
|
|
451
418
|
def green(cls) -> "Color": return Color(0,255,0)
|
|
452
419
|
@classmethod
|
|
453
420
|
def blue(cls) -> "Color": return Color(0,0,255)
|
|
421
|
+
|
|
422
|
+
# @classmethod
|
|
423
|
+
# def (cls) -> "Color": return Color(0,0,255)
|
|
454
424
|
|
|
455
425
|
@classmethod
|
|
456
426
|
def randomize(cls) -> "Color":
|
|
457
427
|
return Color(__randint__(0,255), __randint__(0,255), __randint__(0,255))
|
|
458
428
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
429
|
+
|
|
430
|
+
WHITE_COLOR = Color.white()
|
|
431
|
+
BLACK_COLOR = Color.black()
|
|
432
|
+
RED_COLOR = Color.red()
|
|
433
|
+
GREEN_COLOR = Color.green()
|
|
434
|
+
BLUE_COLOR = Color.blue()
|
|
435
|
+
|
|
436
|
+
WHITE_COLOR_PYG = WHITE_COLOR()
|
|
437
|
+
BLACK_COLOR_PYG = BLACK_COLOR()
|
|
438
|
+
RED_COLOR_PYG = RED_COLOR()
|
|
439
|
+
GREEN_COLOR_PYG = GREEN_COLOR()
|
|
440
|
+
BLUE_COLOR_PYG = BLUE_COLOR()
|