A BPY plus module to simplify work with colors.
Usage example
1 2 3 4 5 6 7 8 |
from .bpy_plus.color import Color col_1 = (0.8, 0.8, 0.8, 1.0) col_2 = (0.8, 0.8, 0.7, 1.0) print(Color.equal(color_1=col_1, color_2=col_2)) # False |
Color class
equal(color_1, color_2, , rel_tol=1e-09, abs_tol=0.0001)
Compares two colors, return True if they are equal and False if not.
Parameters:
color_1: color to compare
color_2: color to compare
rel_tol: relative tolerance
abs_tol: absolute tolerance
Returns:
Compare result – True or False
random(alpha=False)
Returns random color
Parameters:
alpha: if True – return random alpha too, else return alpha = 1.0
Returns:
A tuple with random color values.
linear_to_srgb(color_value)
Convert color value from Linear color space (Blender native) to sRGB color space
Parameters:
color_value: color value in Linear color space in 0.0 … 1.0 range
Returns:
color value in sRGB color space in 0 – 255 range
1 2 3 4 5 |
from bpy_plus.color import Color print(Color.linear_to_srgb(0.5)) # 188 |
srgb_to_linear(color_value)
Convert color value from sRGB color space to Linear color space (Blender native)
Parameters:
color_value: color_value: color value in sRGB color space in 0 – 255 range
Returns:
color value in Linear color space in 0.0 – 1.0 range
1 2 3 4 5 |
from bpy_plus.color import Color print(Color.srgb_to_linear(188)) # 0.4985538322339967 |
rgba_to_rgb565(rgba)
Convert color from RGBA format to RGB565 format
Parameters:
rgba: color in RGBA format, list/tuple of 4 color components (R, G, B, A) in range (0-255, 0-255, 0-255, 0-255)
Returns:
color in RGB565 format, 2-bytes int, in 0-65535 range
1 2 3 4 5 |
from bpy_plus.color import Color print(Color.rgba_to_rgb565((255, 0, 0, 1))) # 63488 |