# Module `StdLib.Color`

A defines module for retrieving colors by name.

Extends the Factorio defines table.

## Functions

set ([color=white[, alpha=1]]) | Set a value for the alpha channel in the given color table.
to_table (c_arr) | Converts a color in the array format to a color in the table format.
from_rgb ([r=0[, g=0[, b=0[, a=255]]]]) | Converts a color in the rgb format to a color table
from_hex (hex[, alpha=1]) | Get a color table with a hexadecimal string.
to_rgb (color) | Converts a color in the color table format to rgb
to_hex (color) | Converts a color in the color table format to hex

## Tables

defines.color | A table of colors allowing retrieval by color name.
defines.anticolor | Returns white for dark colors or black for lighter colors.
defines.lightcolor | Returns a lighter color of a named color
defines.textcolor | Returns a lighter color of a named color.

## Functions

set ([color=white[, alpha=1]])
  Set a value for the alpha channel in the given color table. `color.a` represents the alpha channel in the given color table.
  - If ***alpha*** is given, set `color.a` to it.
  - If ***alpha*** is not given, and if the given color table does not have a value for `color.a`, set `color.a` to 1.
  - If ***alpha*** is not given, and if the given color table already has a value for `color.a`, then leave `color.a` alone.

  ### Parameters:

  - color defines.color or Concepts.Color the color to configure (default white)
  - alpha float the alpha value (*[0 - 1]*) to set for the given color (default 1)

  ### Returns:

  a color table that has the specified value for the alpha channel
to_table (c_arr)
  Converts a color in the array format to a color in the table format.

  ### Parameters:

  - c_arr table the color to convert

  ### Returns:

  a converted color — { r = c\_arr[1], g = c\_arr[2], b = c\_arr[3], a = c\_arr[4] }
from_rgb ([r=0[, g=0[, b=0[, a=255]]]])
  Converts a color in the rgb format to a color table

  ### Parameters:

  - r int 0-255 red (default 0)
  - g int 0-255 green (default 0)
  - b int 0-255 blue (default 0)
  - a int 0-255 alpha (default 255)

  ### Returns:

  Concepts.Color
from_hex (hex[, alpha=1])
  Get a color table with a hexadecimal string. Optionally provide the value for the alpha channel.

  ### Parameters:

  - hex string hexadecimal color string (#ffffff, not #fff)
  - alpha float the alpha value to set; such that ***[ 0 ⋜ value ⋜ 1 ]*** (default 1)

  ### Returns:

  a color table with RGB converted from Hex and with alpha
to_rgb (color)
  Converts a color in the color table format to rgb

  ### Parameters:

  - color table the color to convert

  ### Returns:

  table the color as rgb
to_hex (color)
  Converts a color in the color table format to hex

  ### Parameters:

  - color table the color to convert

  ### Returns:

  string the color as hex

## Tables

defines.color
  A table of colors allowing retrieval by color name.

  ### Fields:

  - white {r=1.00,g=1.00,b=1.00}
  - black {r=0.00,g=0.00,b=0.00}
  - darkgrey {r=0.25,g=0.25,b=0.25}
  - grey {r=0.50,g=0.50,b=0.50}
  - lightgrey {r=0.75,g=0.75,b=0.75}
  - red {r=1.00,g=0.00,b=0.00}
  - darkred {r=0.50,g=0.00,b=0.00}
  - lightred {r=1.00,g=0.50,b=0.50}
  - green {r=0.00,g=1.00,b=0.00}
  - darkgreen {r=0.00,g=0.50,b=0.00}
  - lightgreen {r=0.50,g=1.00,b=0.50}
  - blue {r=0.00,g=0.00,b=1.00}
  - darkblue {r=0.00,g=0.00,b=0.50}
  - lightblue {r=0.50,g=0.50,b=1.00}
  - orange {r=1.00,g=0.55,b=0.10}
  - yellow {r=1.00,g=1.00,b=0.00}
  - pink {r=1.00,g=0.00,b=1.00}
  - purple {r=0.60,g=0.10,b=0.60}
  - brown {r=0.60,g=0.40,b=0.10}
defines.anticolor
  Returns white for dark colors or black for lighter colors.

  ### Fields:

  - green defines.color.black
  - grey defines.color.black
  - lightblue defines.color.black
  - lightgreen defines.color.black
  - lightgrey defines.color.black
  - lightred defines.color.black
  - orange defines.color.black
  - white defines.color.black
  - yellow defines.color.black
  - black defines.color.white
  - blue defines.color.white
  - brown defines.color.white
  - darkblue defines.color.white
  - darkgreen defines.color.white
  - darkgrey defines.color.white
  - darkred defines.color.white
  - pink defines.color.white
  - purple defines.color.white
  - red defines.color.white
defines.lightcolor
  Returns a lighter color of a named color

  ### Fields:

  - white defines.color.lightgrey
  - grey defines.color.darkgrey
  - lightgrey defines.color.grey
  - red defines.color.lightred
  - green defines.color.lightgreen
  - blue defines.color.lightblue
  - yellow defines.color.orange
  - pink defines.color.purple
defines.textcolor
  Returns a lighter color of a named color.

  ### Fields:

  - info {r=0.21,g=0.95,b=1.00}
  - bg {r=0.00,g=0.00,b=0.00}
  - low {r=0.18,g=0.77,b=0.18}
  - med {r=1.00,g=0.89,b=0.26}
  - high {r=1.00,g=0.33,b=0.00}
  - crit {r=1.00,g=0.00,b=0.00}

generated by LDoc 1.4.6 Last updated 2018-06-07 12:58:23