X-Git-Url: http://dolda2000.com/gitweb/?a=blobdiff_plain;f=src%2Fkaka%2Fcakelight%2FColor.java;h=1e92da9c193d5052b3ed0963a27948308042f76a;hb=65af4342c4259d9b99de31a65be58cb1ec4e524d;hp=ba85866aa98eb2fe1c030d60dc32f4373fc3024b;hpb=242486dc84c4f5b0c1bfad9807099355246f4ee2;p=kaka%2Fcakelight.git diff --git a/src/kaka/cakelight/Color.java b/src/kaka/cakelight/Color.java index ba85866..1e92da9 100644 --- a/src/kaka/cakelight/Color.java +++ b/src/kaka/cakelight/Color.java @@ -3,6 +3,10 @@ package kaka.cakelight; public class Color { private int r, g, b; + public static Color rgb(double r, double g, double b) { + return rgb((int)(255 * r), (int)(255 * g), (int)(255 * b)); + } + public static Color rgb(int r, int g, int b) { Color c = new Color(); c.r = r; @@ -11,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; }