Color

o1.gui.Color
See theColor companion object
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.*.

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

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Concrete methods

def darker: Color

Returns a color that is somewhat darker than this one.

Returns a color that is somewhat darker than this one.

Attributes

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)

Attributes

See also

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).

Attributes

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.)

Attributes

Definition Classes
Any
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)

Attributes

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

Attributes

def lighter: Color

Returns a color that is somewhat lighter than this one.

Returns a color that is somewhat lighter than this one.

Attributes

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.

Attributes

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.

Attributes

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

Attributes

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)

Attributes

See also
Definition Classes
Any

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).

Attributes

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.

Attributes

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

Attributes

Returns

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

val opacity: Int
val red: Int