Module Color
A defines module for retrieving colors by name.
Extends the Factorio defines table.
Usage:
require('stdlib/defines/color')
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. |
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. |
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:
-
Concepts.Color
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:
-
Concepts.Color
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:
-
Concepts.Color
a color table with RGB converted from Hex and with alpha
Tables
- defines.color
-
A table of colors allowing retrieval by color name.
Fields:
- white Concepts.Color
- black Concepts.Color
- darkgrey Concepts.Color
- grey Concepts.Color
- lightgrey Concepts.Color
- red Concepts.Color
- darkred Concepts.Color
- lightred Concepts.Color
- green Concepts.Color
- darkgreen Concepts.Color
- lightgreen Concepts.Color
- blue Concepts.Color
- darkblue Concepts.Color
- lightblue Concepts.Color
- orange Concepts.Color
- yellow Concepts.Color
- pink Concepts.Color
- purple Concepts.Color
- brown Concepts.Color
Usage:
color = defines.color.red
- defines.anticolor
-
Returns white for dark colors or black for lighter colors.
Fields:
- green Concepts.Color defines.color.black
- grey Concepts.Color defines.color.black
- lightblue Concepts.Color defines.color.black
- lightgreen Concepts.Color defines.color.black
- lightgrey Concepts.Color defines.color.black
- lightred Concepts.Color defines.color.black
- orange Concepts.Color defines.color.black
- white Concepts.Color defines.color.black
- yellow Concepts.Color defines.color.black
- black Concepts.Color defines.color.white
- blue Concepts.Color defines.color.white
- brown Concepts.Color defines.color.white
- darkblue Concepts.Color defines.color.white
- darkgreen Concepts.Color defines.color.white
- darkgrey Concepts.Color defines.color.white
- darkred Concepts.Color defines.color.white
- pink Concepts.Color defines.color.white
- purple Concepts.Color defines.color.white
- red Concepts.Color defines.color.white
- defines.lightcolor
-
Returns a lighter color of a named color.
Fields:
- white Concepts.Color defines.color.lightgrey
- grey Concepts.Color defines.color.darkgrey
- lightgrey Concepts.Color defines.color.grey
- red Concepts.Color defines.color.lightred
- green Concepts.Color defines.color.lightgreen
- blue Concepts.Color defines.color.lightblue
- yellow Concepts.Color defines.color.orange
- pink Concepts.Color defines.color.purple