/** RGB colors * (Note that java.awt.Color is also a predefined Java class) * @author: Phil Gage */ class Color { /** Red, Green, Blue range 0.0 to 1.0 */ public double r, g, b; Color () {} // Color () { // this.r = 0.5; // default gray // this.g = 0.5; // this.b = 0.5; // } Color (Color c) { this.r = c.r; this.g = c.g; this.b = c.b; } Color (double r, double g, double b) { this.r = r; this.g = g; this.b = b; } void set (Color c) { this.r = c.r; this.g = c.g; this.b = c.b; } void add (Color c) { this.r += c.r; this.g += c.g; this.b += c.b; } void addScaled (double k, Color c) { this.r += k*c.r; this.g += k*c.g; this.b += k*c.b; } void multiply (Color c) { this.r *= c.r; this.g *= c.g; this.b *= c.b; } /** Compare colors */ public boolean equals (Color c) { return this.r == c.r && this.g == c.g && this.b == c.b; } // Define some common colors public static final Color BLACK = new Color (0.0, 0.0, 0.0); public static final Color WHITE = new Color (1.0, 1.0, 1.0); public static final Color GRAY = new Color (0.5, 0.5, 0.5); public static final Color RED = new Color (1.0, 0.0, 0.0); public static final Color GREEN = new Color (0.0, 1.0, 0.0); public static final Color BLUE = new Color (0.0, 0.0, 1.0); public static final Color CYAN = new Color (0.0, 1.0, 1.0); public static final Color MAGENTA = new Color (1.0, 0.0, 1.0); public static final Color YELLOW = new Color (1.0, 1.0, 0.0); }