-
Notifications
You must be signed in to change notification settings - Fork 2
/
color_converter.py
40 lines (26 loc) · 1.08 KB
/
color_converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from .colors import *
class ColorConverter:
@staticmethod
def rgb_to_hex(rgb: RGB) -> HEX:
return HEX(rgb.to_hex())
@staticmethod
def hex_to_rgb(hex: HEX) -> RGB:
return RGB(*hex.to_rgb())
@staticmethod
def rgba_to_hexa(rgba: RGBA) -> HEXA:
return None
@staticmethod
def hexa_to_rgba(hexa: HEXA) -> RGBA:
return None
@staticmethod
def mix_rgb(*colors: RGB) -> RGB:
count = len(colors)
result = [0, 0, 0]
for rgb in colors: result = [result[0] + rgb.color[0], result[1] + rgb.color[1], result[2] + rgb.color[2]]
return RGB(*map(lambda color: color // count, result))
@staticmethod
def mix_rgba(*colors: RGBA) -> RGBA:
count = len(colors)
result = [0, 0, 0, 0]
for rgb in colors: result = [result[0] + rgb.color[0], result[1] + rgb.color[1], result[2] + rgb.color[2], result[3] + rgb.color[3]]
return RGBA(*map(lambda color: color // count, result[:-1]), round(result[-1] / count, 2))