Color_Interpolation module

rgb_to_hsv

procedure · 2 overloadsSource

Converts a red, green, blue color (channels in [0, 1]) to hue in degrees [0, 360), saturation and value in [0, 1]. Takes a Vector3 and returns a Vector3, or takes r, g, b and returns h, s, v. Greys (no difference between channels) give hue 0 and black gives saturation 0.

ExampleOpen in playground ↗
#import "Math";
assert(rgb_to_hsv(xyz(1, 0, 0)) == xyz(0, 1, 1));
h, s, v := rgb_to_hsv(0, 0, 0.5);
assert(h == 240 && s == 1 && v == 0.5);
assert(rgb_to_hsv(xyz(0.5, 0.5, 0.5)) == xyz(0, 0, 0.5));
rgb_to_hsv :: (rgb: Vector3) -> Vector3

Parameters

rgb: Vector3

Returns

rgb_to_hsv :: (r: float, g: float, b: float) -> (h: float, s: float, v: float)

Parameters

r: float
g: float
b: float

Returns

h: float
s: float
v: float

See also