DVUI

toColor

Parameters

#
self:HSV
HSV

Source

Implementation

#
pub fn toColor(self: HSV) Color {
        const c = self.v * self.s;
        const x = c * (1 - @abs(@mod(self.h / 60, 2) - 1));
        const m = self.v - c;

        const step: i8 = @trunc(self.h / 60);

        const r, const g, const b = switch (step) {
            0 => .{ c, x, 0 },
            1 => .{ x, c, 0 },
            2 => .{ 0, c, x },
            3 => .{ 0, x, c },
            4 => .{ x, 0, c },
            5 => .{ c, 0, x },
            else => return .magenta, // hue was < 0 or >= 360
        };

        return .{
            .r = @round((r + m) * 255),
            .g = @round((g + m) * 255),
            .b = @round((b + m) * 255),
            .a = @round(self.a * 255),
        };
    }