O1Library Docs
Fall 2026
Docs API

# Color

o1.gui.Color
See the Color companion object
final class Color extends Fill

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 `Color`s 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 color’s opacity, between Color.Min and Color.Max; that is, 0–255

presetName

  the name of a color contant in “regular form”, i.e., with spaces and largely in lower case (e.g., "saddle blue", "Irish green")

red

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

## Attributes

Companion
  object
Graph
Supertypes
  trait Fill
  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

def darker(percentage: Double): Color

Returns a darker version of this color.

Returns a darker version of this color.

## Parameters

percentage

  the percentage to darken the color by, in the range [0, 100]

## Attributes

def description: String

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

  name, toString

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

## Attributes

override def equals(other: Any): Boolean

Determines if this `Color` equals another object. It does if and 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 and 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

def intensity: Double

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 isOpaque: Boolean

Returns true if and only if this color’s opacity equals Color.Max (which equals 255).

Returns true if and only if this color’s opacity equals Color.Max (which equals 255).

## Attributes

def isTransparent: Boolean

Returns true if and only if this color’s opacity is zero.

Returns true if and only if this color’s opacity is zero.

## 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

def lighter(percentage: Double): Color

Returns a lighter version of this color.

Returns a lighter version of this color.

## Parameters

percentage

  the percentage to lighten the color by, in the range [0, 100]

## Attributes

def name: Option[String]

If this color matches one of the named preset colors, returns that name; `None` otherwise. If 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. If this color matches multiple preset colors, uses one of those names.

## Attributes

See also

  description, toString

def negative: Color

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

def saturation: Double

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

def swingPaint: Option[Paint]

Returns a `Paint` object that corresponds to this color, for the purpose of using this color as a Fill in Swing GUIs. On `Color` objects, this method never returns `None`.

Returns a `Paint` object that corresponds to this color, for the purpose of using this color as a Fill in Swing GUIs. On `Color` objects, this method never returns `None`.

## 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

  name, description

Definition Classes
  Any

def toSwingColor: Color

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

Returns the java.awt.Color equivalent of 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