lighting-controller/color_utils.py

24 lines
806 B
Python
Raw Permalink Normal View History

2024-08-30 05:23:16 +00:00
def adjust_brightness(color, brightness):
"""Adjust brightness of an RGB color."""
r, g, b = color
return (int(r * brightness/255), int(g * brightness/255), int(b * brightness/255))
def rgb_to_hex(color):
"""Convert an RGB color to hex format."""
return '#{:02x}{:02x}{:02x}'.format(color[0], color[1], color[2])
def generate_color_transition(start_color, end_color, steps):
"""Generate a list of colors transitioning from start_color to end_color."""
r1, g1, b1 = start_color
r2, g2, b2 = end_color
transition_colors = []
for i in range(steps):
r = r1 + (r2 - r1) * i // (steps - 1)
g = g1 + (g2 - g1) * i // (steps - 1)
b = b1 + (b2 - b1) * i // (steps - 1)
transition_colors.append((r, g, b))
return transition_colors