Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit 076d69d

Browse files
author
DirectiveAthena
committed
Feature: Better defined Color Classes
1 parent 626173c commit 076d69d

File tree

6 files changed

+157
-34
lines changed

6 files changed

+157
-34
lines changed

src/AthenaColor/BASE.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# - Package Imports -
33
# ----------------------------------------------------------------------------------------------------------------------
44
# General Packages
5+
from __future__ import annotations
56

67
# Custom Library
78

@@ -19,3 +20,106 @@ class end_codes:
1920
cursor_line_previous = "F"
2021
cursor_to_column = "G"
2122
color = "m"
23+
24+
25+
class ColorClass:
26+
# ------------------------------------------------------------------------------------------------------------------
27+
# Conversion Methods
28+
# ------------------------------------------------------------------------------------------------------------------
29+
def to_hexadecimal(self) -> str:
30+
return NotImplemented
31+
def to_cmyk(self) -> tuple[float, float, float, float]:
32+
return NotImplemented
33+
def to_hsl(self) -> tuple[float, float, float]:
34+
return NotImplemented
35+
def to_hsv(self) -> tuple[float, float, float]:
36+
return NotImplemented
37+
38+
# ------------------------------------------------------------------------------------------------------------------
39+
# MAGIC Methods
40+
# ------------------------------------------------------------------------------------------------------------------
41+
# String magic methods
42+
def __str__(self) -> str:
43+
return NotImplemented
44+
45+
def __repr__(self) -> str:
46+
return NotImplemented
47+
48+
# Comparison operators
49+
# >
50+
def __gt__(self, other: ColorClass | int | float) -> bool:
51+
return NotImplemented
52+
53+
# <
54+
def __lt__(self, other: ColorClass | int | float) -> bool:
55+
return NotImplemented
56+
57+
# ==
58+
def __eq__(self, other: ColorClass | int | float) -> bool:
59+
return NotImplemented
60+
61+
# !=
62+
def __ne__(self, other: ColorClass | int | float) -> bool:
63+
return NotImplemented
64+
65+
# <=
66+
def __le__(self, other: ColorClass | int | float) -> bool:
67+
return NotImplemented
68+
69+
# >=
70+
def __ge__(self, other: ColorClass | int | float) -> bool:
71+
return NotImplemented
72+
73+
# math operators
74+
# +
75+
def __add__(self, other: ColorClass | int | float) -> ColorClass:
76+
return NotImplemented
77+
78+
# -
79+
def __sub__(self, other: ColorClass | int | float) -> ColorClass:
80+
return NotImplemented
81+
82+
# *
83+
def __mul__(self, other: ColorClass | int | float) -> ColorClass:
84+
return NotImplemented
85+
86+
# //
87+
def __floordiv__(self, other: ColorClass | int | float) -> ColorClass:
88+
return NotImplemented
89+
90+
# /
91+
def __truediv__(self, other: ColorClass | int | float) -> ColorClass:
92+
return NotImplemented
93+
94+
# %
95+
def __mod__(self, other: ColorClass | int | float) -> ColorClass:
96+
return NotImplemented
97+
98+
# **
99+
def __pow__(self, other: ColorClass | int | float) -> ColorClass:
100+
return NotImplemented
101+
102+
# Augmented assignments
103+
# +=
104+
def __iadd__(self, other: ColorClass | int | float) -> ColorClass:
105+
return self.__add__(other)
106+
107+
# -=
108+
def __isub__(self, other: ColorClass | int | float) -> ColorClass:
109+
return self.__sub__(other)
110+
111+
# *=
112+
def __imul__(self, other: ColorClass | int | float) -> ColorClass:
113+
return self.__mul__(other)
114+
# //=
115+
def __ifloordiv__(self, other: ColorClass | int | float) -> ColorClass:
116+
return self.__floordiv__(other)
117+
# /=
118+
def __itruediv__(self, other: ColorClass | int | float) -> ColorClass:
119+
return self.__truediv__(other)
120+
# %=
121+
def __imod__(self, other: ColorClass | int | float) -> ColorClass:
122+
return self.__mod__(other)
123+
# **=
124+
def __ipow__(self, other: ColorClass | int | float) -> ColorClass:
125+
return self.__pow__(other)

src/AthenaColor/Objects/Hexadecimal.py renamed to src/AthenaColor/Objects/ColorClasses/Hexadecimal.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,26 @@
77

88
# Custom Packages
99
from .Rgb import rgb
10-
from ..Functions.ColorConversion import hexadecimal_to_rgb
10+
from ...Functions.ColorConversion import (
11+
hexadecimal_to_rgb,
12+
rgb_to_hexadecimal
13+
)
14+
1115

1216
# ----------------------------------------------------------------------------------------------------------------------
1317
# - Code -
1418
# ----------------------------------------------------------------------------------------------------------------------
19+
# inherits from rgb as it is just another notation of the rgb format
1520
class hexadecimal(rgb):
21+
def __init__(self, hex_value:str):
22+
self.r,self.g,self.b = hexadecimal_to_rgb(hex_value)
23+
1624
# ------------------------------------------------------------------------------------------------------------------
17-
# INIT method
25+
# MAGIC Methods
1826
# ------------------------------------------------------------------------------------------------------------------
19-
def __init__(self, hex_value:str):
20-
self.r, self.g, self.b = hexadecimal_to_rgb(hex_value)
27+
# String magic methods
28+
def __str__(self) -> str:
29+
return rgb_to_hexadecimal(self.r,self.g,self.b)
30+
31+
def __repr__(self) -> str:
32+
return f"hexadecimal(r={self.r},g={self.g},b={self.b})"

src/AthenaColor/Objects/Rgb.py renamed to src/AthenaColor/Objects/ColorClasses/Rgb.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
# Custom Library
88

99
# Custom Packages
10-
from ..Functions.ColorConversion import rgb_to_hexadecimal
10+
from ...BASE import ColorClass
11+
from ...Functions.ColorConversion import (
12+
rgb_to_hexadecimal,
13+
rgb_to_hsl,
14+
rgb_to_cmyk,
15+
rgb_to_hsv
16+
)
1117

1218
# ----------------------------------------------------------------------------------------------------------------------
1319
# - Code -
@@ -22,7 +28,7 @@ def boundary(value:int|float) -> int|float:
2228
else:
2329
ValueError("Value out of range")
2430

25-
class rgb:
31+
class rgb(ColorClass):
2632
# ------------------------------------------------------------------------------------------------------------------
2733
# INIT method
2834
# ------------------------------------------------------------------------------------------------------------------
@@ -78,12 +84,30 @@ def increase(self, value:float):
7884
# ------------------------------------------------------------------------------------------------------------------
7985
# Conversion Methods
8086
# ------------------------------------------------------------------------------------------------------------------
81-
def hexadecimal(self) -> str:
87+
def to_hexadecimal(self) -> str:
8288
return rgb_to_hexadecimal(
8389
r=self.r,
8490
g=self.g,
8591
b=self.b
8692
)
93+
def to_cmyk(self) -> tuple[float,float,float,float]:
94+
return rgb_to_cmyk(
95+
r=self.r,
96+
g=self.g,
97+
b=self.b
98+
)
99+
def to_hsl(self) -> tuple[float,float,float]:
100+
return rgb_to_hsl(
101+
r=self.r,
102+
g=self.g,
103+
b=self.b
104+
)
105+
def to_hsv(self) -> tuple[float,float,float]:
106+
return rgb_to_hsv(
107+
r=self.r,
108+
g=self.g,
109+
b=self.b
110+
)
87111

88112
# ------------------------------------------------------------------------------------------------------------------
89113
# MAGIC Methods
@@ -247,27 +271,4 @@ def __pow__(self, other: rgb | int | float) -> rgb:
247271
self.b = self.b ** other
248272
return self
249273
else:
250-
return NotImplemented
251-
252-
# Augmented assignments
253-
# +=
254-
def __iadd__(self, other: rgb | int | float) -> rgb:
255-
return self.__add__(other)
256-
# -=
257-
def __isub__(self, other: rgb | int | float) -> rgb:
258-
return self.__sub__(other)
259-
# *=
260-
def __imul__(self, other: rgb | int | float) -> rgb:
261-
return self.__mul__(other)
262-
# //=
263-
def __ifloordiv__(self, other: rgb | int | float) -> rgb:
264-
return self.__floordiv__(other)
265-
# /=
266-
def __itruediv__(self, other: rgb | int | float) -> rgb:
267-
return self.__truediv__(other)
268-
# %=
269-
def __imod__(self, other: rgb | int | float) -> rgb:
270-
return self.__mod__(other)
271-
# **=
272-
def __ipow__(self, other: rgb | int | float) -> rgb:
273-
return self.__pow__(other)
274+
return NotImplemented
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from .Rgb import rgb
2+
from .Hexadecimal import hexadecimal

src/AthenaColor/Objects/HtmlColors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
# Custom Library
77

88
# Custom Packages
9-
from .Rgb import rgb
9+
from .ColorClasses import rgb
1010

1111
# ----------------------------------------------------------------------------------------------------------------------
1212
# - Code -
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
from .HtmlColors import HtmlColors
2-
from .Rgb import rgb
3-
from .Hexadecimal import hexadecimal
2+
3+
4+
from .ColorClasses import (
5+
rgb,
6+
hexadecimal
7+
)

0 commit comments

Comments
 (0)