forked from Contrabang/MapQueueBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_handling.py
30 lines (23 loc) · 906 Bytes
/
color_handling.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
def hex_to_rgb(hex_color):
# Convert hexadecimal to RGB
hex_color = hex_color.lstrip('#')
return tuple(int(hex_color[i:i + 2], 16) for i in (0, 2, 4))
def rgb_to_hex(rgb):
# Convert RGB to hexadecimal
return '#{:02x}{:02x}{:02x}'.format(*rgb)
def blend_hex_colors(color1, color2):
# Convert hex colors to RGB
rgb1 = hex_to_rgb(color1)
rgb2 = hex_to_rgb(color2)
# Calculate the average of each RGB component
avg_rgb = tuple((a + b) // 2 for a, b in zip(rgb1, rgb2))
# Convert the average RGB back to a hexadecimal color
blended_color = rgb_to_hex(avg_rgb)
return blended_color
if __name__ == "__main__":
# Two hex colors to blend
hex_color1 = "#FF5733"
hex_color2 = "#33FF77"
# Get the average color
average_color = blend_hex_colors(hex_color1, hex_color2)
print("Average color:", average_color)