Normand Briere
2018-07-07 e416acb9b012b17d1efe49ad2199ea7132d874d1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package timeflow.util;
 
import java.awt.*;
import java.awt.image.*;
 
public class ColorUtils
{
   
   public static Color alpha(Color c, int a)
   {
       return new Color(c.getRed(), c.getGreen(), c.getBlue(),a);
   }
   
   public static Color interpolate(Color x, Color y, double u)
   {
       return new Color(interp(x.getRed(), y.getRed(), u), 
                        interp(x.getGreen(), y.getGreen(), u),
                        interp(x.getBlue(), y.getBlue(), u));
   }
   
   private static int interp(int x, int y, double u)
   {
       return (int)(y*u+x*(1-u));
   }
   
   public static float[] hsb(Color c)
   {
       return Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), new float[3]);
   }
   
}