blend_colors(color1, color2, ratio=0.5): Blends two colors in the RGB format using the specified ratio.
RGB to HEX
Converts RGB to HEX
Parameters:
r (int): Red value (0-255).
g (int): Green value (0-255).
b (int): Blue value (0-255).
Returns:
str: A string representing the hex color code (e.g., "#FFFFFF").
HEX to RGB
Converts HEX to RGB
Parameters:
hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").
Returns:
tuple: A tuple representing the RGB values (e.g., (255, 255, 255)).
RGB to HSL
Converts RGB to HSL.
Parameters:
r (int): Red value (0-255).
g (int): Green value (0-255).
b (int): Blue value (0-255).
Returns:
tuple: A tuple representing the HSL values (h, s, l) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
l (float) is lightness in the range [0, 1].
HSL to RGB
Converts HSL to RGB.
Parameters:
h (float): Hue in the range [0, 360).
s (float): Saturation in the range [0, 1].
l (float): Lightness in the range [0, 1].
Returns:
tuple: A tuple representing the RGB values (0-255).
RGB to HSV
Converts RGB to HSV.
Parameters:
r (int): Red value (0-255).
g (int): Green value (0-255).
b (int): Blue value (0-255).
Returns:
tuple: A tuple representing the HSV values (h, s, v) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
v (float) is value in the range [0, 1].
HSV to RGB
Converts HSV to RGB.
Parameters:
h (float): Hue in the range [0, 360).
s (float): Saturation in the range [0, 1].
v (float): Value in the range [0, 1].
Returns:
tuple: A tuple representing the RGB values (0-255).
RGB to CMYK
Converts RGB to CMYK.
Parameters:
r (int): Red value (0-255).
g (int): Green value (0-255).
b (int): Blue value (0-255).
Returns:
tuple: A tuple representing the CMYK values (c, m, y, k) where
c (float) is cyan in the range [0, 1],
m (float) is magenta in the range [0, 1],
y (float) is yellow in the range [0, 1],
k (float) is key/black in the range [0, 1].
HEX to HSL
Converts HEX to HSL.
Parameters:
hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").
Returns:
tuple: A tuple representing the HSL values (h, s, l) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
l (float) is lightness in the range [0, 1].
HEX to HSV
Converts HEX to HSV.
Parameters:
hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").
Returns:
tuple: A tuple representing the HSV values (h, s, v) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
v (float) is value in the range [0, 1].
HEX to CMYK
Converts HEX to CMYK.
Parameters:
hex_value (str): A string representing a hex color code (e.g., "#FFFFFF").
Returns:
tuple: A tuple representing the CMYK values (c, m, y, k) where
c (float) is cyan in the range [0, 1],
m (float) is magenta in the range [0, 1],
y (float) is yellow in the range [0, 1],
k (float) is key/black in the range [0, 1].
HSL to HEX
Converts HSL to HEX.
Parameters:
hsl_value (tuple): A tuple representing the HSL values (h, s, l) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
l (float) is lightness in the range [0, 1].
Returns:
str: A string representing the hex color code (e.g., "#FFFFFF").
Raises:
ValueError: If the HSL values are out of range.
HSL to HSV
Converts HSL to HSV.
Parameters:
hsl_value (tuple): A tuple representing the HSL values (h, s, l) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
l (float) is lightness in the range [0, 1].
Returns:
tuple: A tuple representing the HSV values (h, s, v) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
v (float) is value in the range [0, 1].
Raises:
ValueError: If the HSL values are out of range.
HSL to CMYK
Converts HSL to CMYK.
Parameters:
hsl_value (tuple): A tuple representing the HSL values (h, s, l) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
l (float) is lightness in the range [0, 1].
Returns:
tuple: A tuple representing the CMYK values (c, m, y, k) where
c (float) is cyan in the range [0, 1],
m (float) is magenta in the range [0, 1],
y (float) is yellow in the range [0, 1],
k (float) is key/black in the range [0, 1].
Raises:
ValueError: If the HSL values are out of range.
HSV to HEX
Converts HSV to HEX.
Parameters:
hsv_value (tuple): A tuple representing the HSV values (h, s, v) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
v (float) is value in the range [0, 1].
Returns:
str: A string representing the hex color code (e.g., "#FFFFFF").
Raises:
ValueError: If the HSV values are out of range.
HSV to HSL
Converts HSV to HSL.
Parameters:
hsv_value (tuple): A tuple representing the HSV values (h, s, v) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
v (float) is value in the range [0, 1].
Returns:
tuple: A tuple representing the HSL values (h, s, l) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
l (float) is lightness in the range [0, 1].
Raises:
ValueError: If the HSV values are out of range.
HSV to CMYK
Converts HSV to CMYK.
Parameters:
hsv_value (tuple): A tuple representing the HSV values (h, s, v) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
v (float) is value in the range [0, 1].
Returns:
tuple: A tuple representing the CMYK values (c, m, y, k) where
c (float) is cyan in the range [0, 1],
m (float) is magenta in the range [0, 1],
y (float) is yellow in the range [0, 1],
k (float) is key/black in the range [0, 1].
Raises:
ValueError: If the HSV values are out of range.
CMYK to HSV
Converts CMYK to HSV.
Parameters:
cmyk_value (tuple): A tuple representing the CMYK values (c, m, y, k) where
c (float) is cyan in the range [0, 1],
m (float) is magenta in the range [0, 1],
y (float) is yellow in the range [0, 1],
k (float) is key/black in the range [0, 1].
Returns:
tuple: A tuple representing the HSV values (h, s, v) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
v (float) is value in the range [0, 1].
Raises:
ValueError: If the CMYK values are out of range.
CMYK to HSL
Converts CMYK to HSL.
Parameters:
cmyk_value (tuple): A tuple representing the CMYK values (c, m, y, k) where
c (float) is cyan in the range [0, 1],
m (float) is magenta in the range [0, 1],
y (float) is yellow in the range [0, 1],
k (float) is key/black in the range [0, 1].
Returns:
tuple: A tuple representing the HSL values (h, s, l) where
h (float) is hue in the range [0, 360),
s (float) is saturation in the range [0, 1],
l (float) is lightness in the range [0, 1].
Raises:
ValueError: If the CMYK values are out of range.
CMYK to HEX
Converts CMYK to HEX.
Parameters:
cmyk_value (tuple): A tuple representing the CMYK values (c, m, y, k) where
c (float) is cyan in the range [0, 1],
m (float) is magenta in the range [0, 1],
y (float) is yellow in the range [0, 1],
k (float) is key/black in the range [0, 1].
Returns:
str: A string representing the hex color code (e.g., "#FFFFFF").
Raises:
ValueError: If the CMYK values are out of range.
Blend colors
Blends two colors in the RGB format using the specified ratio.
Parameters:
color1 (tuple): The first RGB color as a tuple of three integers (R, G, B).
color2 (tuple): The second RGB color as a tuple of three integers (R, G, B).
ratio (float, optional): The ratio to blend the colors. A value of 0.5 will
blend both colors equally. Values closer to 0 will
give more weight to `color1`, and values closer to
1 will favor `color2`. Default is 0.5.
Returns:
tuple: The blended color as an RGB tuple of three integers.
Example:
>>> blend_colors((255, 0, 0), (0, 0, 255), 0.5)
(127, 0, 127)