Color

object Color

This companion object of class Color provides methods for creating new Color objects. There is also a small selection of related utility methods and constants.

For many constants of type Color that represent different preset colors, see o1.gui.colors.

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

Companion:
class
class Object
trait Matchable
class Any
Color.type

Value members

Concrete methods

def apply(red: Double, green: Double, blue: Double): Color

Creates a new fully opaque Color with the given RGB components.

Creates a new fully opaque Color with the given RGB components.

Value parameters:
blue

the amount of blue in the color; values outside the 0–255 range are clamped to fit it

green

the amount of green in the color; values outside the 0–255 range are clamped to fit it

red

the amount of red in the color; values outside the 0–255 range are clamped to fit it

Returns:

the color

def apply(red: Double, green: Double, blue: Double, opacity: Double): Color

Creates a new Color with the given RGB components and opacity.

Creates a new Color with the given RGB components and opacity.

Value parameters:
blue

the amount of blue in the color; values outside the 0–255 range are clamped to fit it

green

the amount of green in the color; values outside the 0–255 range are clamped to fit it

opacity

the opacity of the color; values outside the 0–255 range are clamped to fit it

red

the amount of red in the color; values outside the 0–255 range are clamped to fit it

Returns:

the color

def fromHSI(hue: Double, saturation: Double, value: Double, opacity: Double): Color

Creates a Color specified in terms of the HSI (hue—saturation—intensity) color scheme.

Creates a Color specified in terms of the HSI (hue—saturation—intensity) color scheme.

Value parameters:
hue

the hue (“main observable color”) component of color, in degrees around the color wheel (0–360)

opacity

the color’s opacity; if unspecified, defaults to fully opaque (Color.Max)

saturation

the saturation (“richness”) component of the color; values outside the 0–255 range are clamped to fit it

value

the intensity (“brightness”) component of the color; values outside the 0–255 range are clamped to fit it

Returns:

the color (represented internally as RGB nonetheless)

def unapply(color: Color): Option[(Int, Int, Int, Int)]

Deconstructs a Color to its components and returns them as a tuple. Its presence here in the companion object enables us to write things like:

Deconstructs a Color to its components and returns them as a tuple. Its presence here in the companion object enables us to write things like:

myColor match
 case Color(r, g, b, 255)          => "opaque color: " + r + "," + g + "," + b
 case Color(r, _, _, _) if r > 200 => "high in red"
 case _                            => "other color"
Value parameters:
color

any color

Returns:

a Some that contains a tuple with all the RGB components of the given color and its opacity

Concrete fields

val Max: Int

The maximum value of a Color’s RGB and opacity components. (They range between 0 and 255, so this equals 255.)

The maximum value of a Color’s RGB and opacity components. (They range between 0 and 255, so this equals 255.)

val Min: Int

The minimum value of a Color’s RGB and opacity components. (They range between 0 and 255, so this equals zero.)

The minimum value of a Color’s RGB and opacity components. (They range between 0 and 255, so this equals zero.)

Givens