Color

final class Color

Each instance of this class represents a color. The class uses the RGB color scheme: each color is a combination of a red, green, and blue components; there’s also a fourth component of opacity. Color objects are immutable.

You don’t instantiate Color directly; instead, you create Colors with the methods on the Color companion object (e.g. Color(200, 150, 255)) or use one of the named color constants in o1.gui.colors. There are also a few methods in this class that returns new Color objects defined in terms of existing ones (e.g., lighter, edit).

This class has an alias in the top-level package o1, so it’s accessible to students simply via import o1.*.

Value parameters:
blue

the amount of blue in the color, between Color.Min and Color.Max; that is, 0–255

green

the amount of green in the color, between Color.Min and Color.Max; that is, 0–255

opacity

the opacity of the color, between Color.Min and Color.Max; that is, 0–255

red

the amount of red in the color, between Color.Min and Color.Max; that is, 0–255

Companion:
object
class Object
trait Matchable
class Any

Value members

Concrete methods

Returns a color that is somewhat darker than this one.

Returns a color that is somewhat darker than this one.

Returns a string description of this color, using preset color names where possible. This description reflects the color’s RGB values and opacity. Examples:

Returns a string description of this color, using preset color names where possible. This description reflects the color’s RGB values and opacity. Examples:

  • "Color(200, 100, 200)" (opaque custom color)
  • "transparent Color(200, 100, 200, 0)" (fully transparent custom color)
  • "translucent Color(200, 100, 200, 50)" (non-opaque, non-transparent custom color)
  • "opaque Brown" (opaque color with RGB values 165, 42, and 42 — whether the constant LightGreen or an identical custom color)
  • "opaque Brown" (non-opaque color with RGB values 165, 42, and 42)
  • "transparent Brown" (fully transparent custom color with RGB values 165, 42, and 42)
  • "translucent Brown" (non-opaque, non-transparent custom color with RGB values 165, 42, and 42)
See also:
def edit(red: Int, green: Int, blue: Int, opacity: Int): Color

Returns a color with the specified color components. The parameters default to this Color object’s component values, so you can specify just the ones you want to change, as in myColor.edit(red = 255, opacity = 100).

Returns a color with the specified color components. The parameters default to this Color object’s component values, so you can specify just the ones you want to change, as in myColor.edit(red = 255, opacity = 100).

override def equals(other: Any): Boolean

Determines if this Color equals another object. It does if an only if the other object is also a Color and its red, green, blue, and opacity components are equal to this Color’s. (Any names the colors may have are irrelevant.)

Determines if this Color equals another object. It does if an only if the other object is also a Color and its red, green, blue, and opacity components are equal to this Color’s. (Any names the colors may have are irrelevant.)

Definition Classes
def hue: Double

the hue (“main observable color”) component of this color when viewed in the HSI color scheme, in degrees around the color wheel (0–360)

the hue (“main observable color”) component of this color when viewed in the HSI color scheme, in degrees around the color wheel (0–360)

the intensity (“brightness”) component of this color when viewed in the HSI color scheme, between Color.Min and Color.Max; that is, 0–255

the intensity (“brightness”) component of this color when viewed in the HSI color scheme, between Color.Min and Color.Max; that is, 0–255

Returns a color that is somewhat lighter than this one.

Returns a color that is somewhat lighter than this one.

If this color matches one of the named preset colors, returns that name; None otherwise. In case this color matches multiple preset colors, uses one of those names.

If this color matches one of the named preset colors, returns that name; None otherwise. In case this color matches multiple preset colors, uses one of those names.

See also:

Returns the color whose R, G, and B components are the complements of this Color object’s respective components (255 minus the value). Opacity is retained.

Returns the color whose R, G, and B components are the complements of this Color object’s respective components (255 minus the value). Opacity is retained.

the saturation (“richness”) component of the color when viewed in the HSI color scheme, between Color.Min and Color.Max; that is, 0–255

the saturation (“richness”) component of the color when viewed in the HSI color scheme, between Color.Min and Color.Max; that is, 0–255

override def toString: String

Returns a string description of this color. This description reflects how the color was created. Examples:

Returns a string description of this color. This description reflects how the color was created. Examples:

  • "Red", "CornflowerBlue" (named preset colors)
  • "Color(200, 100, 200)" (opaque custom color)
  • "Color(200, 100, 200, 50)" (non-opaque custom color)
See also:
Definition Classes

Returns the java.awt.Color equivalent to this color (which is compatible with Swing GUIs).

Returns the java.awt.Color equivalent to this color (which is compatible with Swing GUIs).

Concrete fields

val blue: Int
val green: Int
lazy override val hashCode: Int

A hash code generated for this Color from its four components.

A hash code generated for this Color from its four components.

lazy val hsi: (Double, Double, Double)

the HSI (hue—saturation—intensity) equivalents of this RGB color

the HSI (hue—saturation—intensity) equivalents of this RGB color

Returns:

the three HSI components as a tuple; cf. hue, saturation, and intensity

val red: Int