From c8cc2f442a9f8ee9d9d0365b2193bbfe36faaebf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Mon, 14 Feb 2022 20:36:07 +0100 Subject: [PATCH] Added ColorHSV --- Sandbox/src/ColorHSV.bf | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 Sandbox/src/ColorHSV.bf diff --git a/Sandbox/src/ColorHSV.bf b/Sandbox/src/ColorHSV.bf new file mode 100644 index 0000000..d1f68c9 --- /dev/null +++ b/Sandbox/src/ColorHSV.bf @@ -0,0 +1,43 @@ +using GlitchyEngine.Math; +using System; +namespace Sandbox +{ + struct ColorHSV + { + public float H; + public float S; + public float V; + + public this(float h, float s, float v) + { + H = h; + S = s; + V = v; + } + + public static explicit operator ColorRGB(ColorHSV hsv) + { + float c = hsv.V * hsv.S; + float x = c * (1.0f - Math.Abs((hsv.H / 60.0f) % 2.0f - 1.0f)); + + float m = hsv.V - c; + + ColorRGB rgb_ = ?; + + if (hsv.H < 60.0f) + rgb_ = ColorRGB(c, x, 0); + else if (hsv.H < 120.0f) + rgb_ = ColorRGB(x, c, 0); + else if (hsv.H < 180.0f) + rgb_ = ColorRGB(0, c, x); + else if (hsv.H < 240.0f) + rgb_ = ColorRGB(0, x, c); + else if (hsv.H < 300.0f) + rgb_ = ColorRGB(x, 0, c); + else if (hsv.H < 360.0f) + rgb_ = ColorRGB(c, 0, x); + + return .(rgb_.Red + m, rgb_.Green + m, rgb_.Blue + m); + } + } +} \ No newline at end of file