View Source Scenic.Color (Scenic v0.11.2)

APIs to create and work with colors.

Colors are used in multiple places in Scenic. Fills and Strokes of a single color are quite common.

data-format

Data Format

There are multiple ways to define colors.

The native format of color on modern computers is RGBA. This is four channels including Red, Green, Blue, and Alpha. Alpha indicates transparency, and is used to blend the color being applied at any given location with the color that is already there.

Most of the time, you will use one of the pre-defined named colors from the Named Colors table. However, there are times when you want to work with other color formats ranging from simple grayscale to rgb to hsl.

The following formats are all supported by the Scenic.Color module. The values of r, g, b, and a are integers between 0 and 255. For HSL and HSV, h is a float between 0 and 360, while the s, v and l values are floats between 0 and 100.

FormatImplicitExplicit
Named ColornaSee the Named Color Table
Grayscaleg{:color_g, g}
Gray, Alpha{g, a}{:color_ga, {g, a}}
Red, Green, Blue{r, g, b}{:color_rgb, {r, g, b}}
Red, Green, Blue, Alpha{r, g, b, a}{:color_rgba, {r, g, b, a}}
Hue, Saturation, Valuena{:color_hsv, {h, s, v}}
Hue, Saturation, Lightnessna{:color_hsl, {h, s, l}}

named-colors

Named Colors

The simplest is to used a named color (see the table below). Named colors are simply referred to by an atom, which is their name. Named colors are opaque by default. I failed to figure out how to show a table with colored cells in exdoc. So this is a list of all the color names. I'll eventually add a link to a page that shows them visually.

[:alice_blue, :antique_white, :aqua, :aquamarine, :azure, :beige, :bisque, :black, :blanched_almond, :blue, :blue_violet, :brown, :burly_wood, :cadet_blue, :chartreuse, :chocolate, :coral, :cornflower_blue, :cornsilk, :crimson, :cyan, :dark_blue, :dark_cyan, :dark_golden_rod, :dark_gray, :dark_green, :dark_grey, :dark_khaki, :dark_magenta, :dark_olive_green, :dark_orange, :dark_orchid, :dark_red, :dark_salmon, :dark_sea_green, :dark_slate_blue, :dark_slate_gray, :dark_slate_grey, :dark_turquoise, :dark_violet, :deep_pink, :deep_sky_blue, :dim_gray, :dim_grey, :dodger_blue, :fire_brick, :floral_white, :forest_green, :fuchsia, :gainsboro, :ghost_white, :gold, :golden_rod, :gray, :green, :green_yellow, :grey, :honey_dew, :hot_pink, :indian_red, :indigo, :ivory, :khaki, :lavender, :lavender_blush, :lawn_green, :lemon_chiffon, :light_blue, :light_coral, :light_cyan, :light_golden_rod, :light_golden_rod_yellow, :light_gray, :light_green, :light_grey, :light_pink, :light_salmon, :light_sea_green, :light_sky_blue, :light_slate_gray, :light_slate_grey, :light_steel_blue, :light_yellow, :lime, :lime_green, :linen, :magenta, :maroon, :medium_aqua_marine, :medium_blue, :medium_orchid, :medium_purple, :medium_sea_green, :medium_slate_blue, :medium_spring_green, :medium_turquoise, :medium_violet_red, :midnight_blue, :mint_cream, :misty_rose, :moccasin, :navajo_white, :navy, :old_lace, :olive, :olive_drab, :orange, :orange_red, :orchid, :pale_golden_rod, :pale_green, :pale_turquoise, :pale_violet_red, :papaya_whip, :peach_puff, :peru, :pink, :plum, :powder_blue, :purple, :rebecca_purple, :red, :rosy_brown, :royal_blue, :saddle_brown, :salmon, :sandy_brown, :sea_green, :sea_shell, :sienna, :silver, :sky_blue, :slate_blue, :slate_gray, :slate_grey, :snow, :spring_green, :steel_blue, :tan, :teal, :thistle, :tomato, :turquoise, :violet, :wheat, :white, :white_smoke, :yellow, :yellow_green]

additional-named-colors

Additional Named Colors

NameValue
:clear{0x80, 0x80, 0x80, 0x00}
:transparent{0x80, 0x80, 0x80, 0x00}

converting-between-color-formats

Converting Between Color Formats

By using the functions to_g/1, to_ga/1, to_rgb/1, to_rgb/1, to_hsl/1, and to_hsv/1 you can convert between any implicit or explicit color type to any explicit color type.

Link to this section Summary

Functions

Return map of all named colors and their values

Convert a specified color to G format (just grayscale)

Convert a specified color to GA format

Convert a color to the HSL color space

Convert a color to the HSV color space

Convert a specified color to RGB format

Convert a specified color to RGBA format

Link to this section Types

@type explicit() :: g() | ga() | rgb() | rgba() | hsl() | hsv()
@type g() :: {:color_g, grey :: integer()}
@type ga() :: {:color_ga, {grey :: integer(), alpha :: integer()}}
@type hsl() ::
  {:color_hsl, {hue :: number(), saturation :: number(), lightness :: number()}}
@type hsv() ::
  {:color_hsv, {hue :: number(), saturation :: number(), value :: number()}}
@type implicit() ::
  atom()
  | {name :: atom(), a :: integer()}
  | (gray :: integer())
  | {gray :: integer(), alpha :: integer()}
  | {red :: integer(), green :: integer(), blue :: integer()}
  | {red :: integer(), green :: integer(), blue :: integer(),
     alpha :: integer()}
@type rgb() :: {:color_rgb, {red :: integer(), green :: integer(), blue :: integer()}}
@type rgba() ::
  {:color_rgba,
   {red :: integer(), green :: integer(), blue :: integer(), alpha :: integer()}}
@type t() :: implicit() | explicit()

Link to this section Functions

Return map of all named colors and their values

@spec to_g(color :: t()) :: g()

Convert a specified color to G format (just grayscale)

This is a lossy conversion and will lose any color information other than the gray level.

@spec to_ga(color :: t()) :: ga()

Convert a specified color to GA format

@spec to_hsl(color :: t()) :: hsl()

Convert a color to the HSL color space

@spec to_hsv(color :: t()) :: hsv()

Convert a color to the HSV color space

@spec to_rgb(color :: t()) :: rgb()

Convert a specified color to RGB format

@spec to_rgba(color :: t()) :: rgba()

Convert a specified color to RGBA format