fromColor
Parameters
- color:Color
- Color
Source
Implementation
pub fn fromColor(color: Color) HSV {
const r: f32 = @as(f32, color.r) / 255.0;
const g: f32 = @as(f32, color.g) / 255.0;
const b: f32 = @as(f32, color.b) / 255.0;
const a: f32 = @as(f32, color.a) / 255.0;
const max = @max(r, g, b);
const min = @min(r, g, b);
const delta = max - min;
const h = 60 * (if (delta == 0)
0
else if (max == r)
@mod((g - b) / delta, 6)
else if (max == g)
(b - r) / delta + 2
else if (max == b)
(r - g) / delta + 4
else
unreachable);
const s = if (max == 0) 0 else delta / max;
return .{ .h = h, .s = s, .v = max, .a = a };
}