1 package kaka.cakelight;
6 public static Color rgb(double r, double g, double b) {
7 return rgb((int)(255 * r), (int)(255 * g), (int)(255 * b));
10 public static Color rgb(int r, int g, int b) {
11 Color c = new Color();
18 public static Color hsv(double hue, double saturation, double value) {
19 double normalizedHue = hue - Math.floor(hue);
20 int h = (int)(normalizedHue * 6);
21 double f = normalizedHue * 6 - h;
22 double p = value * (1 - saturation);
23 double q = value * (1 - f * saturation);
24 double t = value * (1 - (1 - f) * saturation);
27 case 0: return rgb(value, t, p);
28 case 1: return rgb(q, value, p);
29 case 2: return rgb(p, value, t);
30 case 3: return rgb(p, q, value);
31 case 4: return rgb(t, p, value);
32 case 5: return rgb(value, p, q);
33 default: throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + ", " + value);
49 public Color interpolate(Color other, double value) {
50 double invertedValue = 1 - value;
52 (int)(r * invertedValue + other.r * value),
53 (int)(g * invertedValue + other.g * value),
54 (int)(b * invertedValue + other.b * value)