Getting Started with dmc-kolor

This is for dmc-kolor 1.0

Get quickly up-and-running with dmc-kolor.

Table of Contents

[toc indent=20px minLevel=2]

Installation

For installation instructions see !! file not found !!.

Import

Import the library module like so:

{code:language=none|title=Import DMC Kolor} local display = require 'dmc_kolor'


That's all that's required. The library does the necessary modifications to the Corona engine so that it just works.



### `setFillColor` and `setStrokeColor`

These standard Corona object methods are re-mapped to allow you to use traditional RGBA color definitions.

{code:language=none|title=Using Re-mapped Standard Color Methods}
local rect1 = display.newRect( 200, 700, 100, 200 )
rect1:setFillColor( 255, 228, 225 )
rect1.strokeWidth = 5
rect1:setStrokeColor( 180, 50, 100 )

By default these methods are mapped to the RGB way, but can be mapped to use the HDR way instead. See DEFAULT_COLOR_SPACE below.

Named Colors

It is possible to define a file which contains named-colors. There are three named-color files which come with the library. They all contain definitions for the X11 colors, but differ in how they describe the color values, either using HEX, RGB or HDR values.

{code:language=none|title=Using Named-Colors}

local newCircle1 = display.newCircle( 150, 375, 30 ) newCircle1:setFillColor( "Chartreuse" ) newCircle1.strokeWidth = 5 newCircle1:setStrokeColor( 150, 150, 150 )




### Additional Color Methods: `setFillRGB`, `setStrokeRGB`, `setFillHDR`, `setStrokeHDR`

Additional methods are attached on to each display object which you create and are available at any time. So instead of using `setFillColor` for example, you can always use `setFillRGB` or `setFillHDR`.

{code:language=none|title=Using Additional Color Methods}
local newCircle2 = display.newCircle( 325, 375, 30 )
newCircle2:setFillRGB( "Chartreuse" )
newCircle2.strokeWidth = 5
newCircle2:setStrokeRGB( 150, 150, 150 )

local newCircle3 = display.newCircle( 500, 375, 30 )
newCircle3:setFillHDR( "Chartreuse" )
newCircle3.strokeWidth = 5
newCircle3:setStrokeHDR( .5, .5, .5 )

dmc_library.cfg Configurations

dmc_kolor has different flags to put into the config file.

NAMED_COLOR_FILE and NAMED_COLOR_FORMAT

This two items work together to define a color mapping file.

NAMED_COLOR_FILE allows you to define a color file which contains name to color mappings in JSON format. There are examples which come with the library.

NAMED_COLOR_FORMAT tells the module what format is used in the color mapping file. Possibilities include RGB, HEX and HDR.

Here is an example: {code:language=none|title=Defining Named Color File and Format} [DMC_KOLOR]

NAMED_COLOR_FILE = named_colors_hex.json NAMED_COLOR_FORMAT = HEX


### Examples:

Here are some examples of a named color file, in each of RGB, HEX, and HDR.


{code:language=none|title=HEX Color File}
{
    "Alice Blue": "F0F8FF",
    "Antique White": "FAEBD7",
    "Aqua": "00FFFF",
    "Aquamarine": "7FFFD4",
    "Azure": "F0FFF"
}

{code:language=none|title=RGB Color File} { "Alice Blue": [ 240, 248, 255 ], "Antique White": [ 250, 235, 215 ], "Aqua": [ 0, 255, 255 ], "Aquamarine": [ 127, 255, 212 ], "Azure": [ 240, 255, 255 ] }


{code:language=none|title=HDR Color File}
{
    "Alice Blue": [ 0.94117647058824, 0.97254901960784, 1 ],
    "Antique White": [ 0.98039215686275, 0.92156862745098, 0.84313725490196 ],
    "Aqua": [ 0, 1, 1 ],
    "Aquamarine": [ 0.49803921568627, 1, 0.83137254901961 ],
    "Azure": [ 0.94117647058824, 1, 1 ]
}

The color definition can also include a value for the alpha channel. See [dmc_kolor Documentation] for more `rmation.

DEFAULT_COLOR_SPACE

This determines which color space to use when the standard methods such as setFillColor are used in the code.

Possibilities include RGB and HDR.

By default the value is RGB.

[DMC_KOLOR]

DEFAULT_COLOR_SPACE = HDR