New shifting color mode
[kaka/cakelight.git] / src / kaka / cakelight / Color.java
index da09127..1e92da9 100644 (file)
@@ -15,6 +15,25 @@ public class Color {
         return c;
     }
 
+    public static Color hsv(double hue, double saturation, double value) {
+        double normalizedHue = hue - Math.floor(hue);
+        int h = (int)(normalizedHue * 6);
+        double f = normalizedHue * 6 - h;
+        double p = value * (1 - saturation);
+        double q = value * (1 - f * saturation);
+        double t = value * (1 - (1 - f) * saturation);
+
+        switch (h) {
+            case 0: return rgb(value, t, p);
+            case 1: return rgb(q, value, p);
+            case 2: return rgb(p, value, t);
+            case 3: return rgb(p, q, value);
+            case 4: return rgb(t, p, value);
+            case 5: return rgb(value, p, q);
+            default: throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
+        }
+    }
+
     public int r() {
         return r;
     }