Color

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

Attributes

Companion
class
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Color.type

Members list

Value members

Concrete methods

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

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

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

Attributes

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

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

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 color’s opacity; 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

Attributes

Creates a new Color with RGB components (and optionally opacity) taken from the given string.

Creates a new Color with RGB components (and optionally opacity) taken from the given string.

Parameters

colorAsHex

a six-character "RRGGBB" or eight-character "RRGGBBAA" hex color. The color is fully opaque unless specified. Examples: "000000" (black), "FFFFFF" (white), "FF00FF" (violet), "FF00FF80" (half-transparent violet). Lower-case inputs such as "ff00ff80" are also valid.

Attributes

Throws
IllegalArgumentException

if the string is not a valid representation of a color

def apply(rgba: Int): Color

Creates a new Color with RGB components and opacity (A) taken from the given integer.

Creates a new Color with RGB components and opacity (A) taken from the given integer.

Parameters

rgba

an integer in RGBA format. Examples: 0x000000FF (opaque black), 0xFFFFFFFF (opaque white), 0xFF00FFFF (opaque violet), 0xFF00FF80 (half-transparent violet).

Attributes

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.

Parameters

hue

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

intensity

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

opacity

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

saturation

the color’s saturation component (“richness”); values outside the 0.0–1.0 range are clamped to fit it

Attributes

Returns

the color (represented internally as RGB nonetheless)

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"

Parameters

color

any color

Attributes

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

Attributes

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

Attributes

Givens