Skip to content

Jerakin/defold-color

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

defold-color

Library to modify, transform and convert colors. To use defined named colors and paletts, generate random colors and get a random palett.

Screenshot from the example/test scene.

Installation

To use the library in a Defold project this project has to be added as a Defold library dependency. Open the game.project file and in the Dependencies field in the Project section add:

https://github.com/Jerakin/defold-color/archive/master.zip

Or point to the ZIP file of a specific release.

Lua API

color

Convert colors between rgb, hsv, and hex

color.from_hex(str)

       Converts a hex string into a color vector.

       PARAMETERS
             • str (string) - The color in a hex format, accepts it with and without th #.
                 It also the supports the shorthand for hex colors.

       RETURN
             • color (vmath.vector4)

color.to_hex(color)

       Converts a color vector into a hex string.

       PARAMETERS
             • color (vmath.vector4) - The color in a vmath.vector4 format, alpha is discarded.

       RETURN
             • string (string) - The hex string.

color.from_table(tbl)

       Converts a table of values into a color vector. There is also a
       color.from_table_255 that assumes values in a 0-255 format.

       PARAMETERS
             • tbl (table) - The color in a {1.0, 1.0, 1.0, 1.0} format (alpha optional, defaults to 1).

       RETURN
             • color (vmath.vector4)

color.to_table(color)

       Transforms the color into a table. There is also a color.to_table_255 that converts
       the values into 0-255 values.

       PARAMETERS
             • color (vmath.vector4)

       RETURN
             • table (table) - The color as a table.

color.from_rgba(r, g, b, a)

       Converts the arguments into a color vector. There is also a color.from_rgba_255 that assumes
       values in a 0-255 format.

       PARAMETERS
             • r (number) - The red component of the color
             • g (number) - The green component of the color
             • b (number) - The blue component of the color
             • a (number) - Optional alpha component of the color ( defualts to 1)

       RETURN
             • color (vmath.vector4)

color.from_hsv(hue, saturation, value)

       Converts h, s, v values into color vector.

       PARAMETERS
             • hue (number) - The hue component of the color
             • saturation (number) - The saturation component of the color
             • value (number) - The value component of the color

       RETURN
             • color (vmath.vector4)

color.to_hsv(color)

       Converts the color to a table of HSV values.

       PARAMETERS
             • color (vmath.vector4)

       RETURN
             • hue (number) - The hue component of the color
             • saturation (number) - The saturation component of the color
             • value (number) - The value component of the color

color.shift(color, value)

       Shift the color along the color wheel.

       PARAMETERS
             • color (vmath.vector4) The starting color to shift.
             • value (number) Percental shift (0-1) around the wheel, defaults to a random value of 1 to 2 percent.

       RETURN
             • color (vmath.vector4)

cmath

Perform arithmetic and blend modes.

cmath.difference(base, blend)

       Looks at the color information in each channel and subtracts the blend color from the base color.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.screen(base, blend)

       Looks at each channel’s color information and multiplies the inverse of the blend and base colors

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.overlay(base, blend)

       Multiplies or screens the colors, depending on the base color.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.invert(color)

       Inverts the color.

       PARAMETERS
             • color (vmath.vector4)

       RETURN              • color (vmath.vector4)

cmath.multiply(base, blend)

       Looks at the color information in each channel and multiplies the base color by the blend color.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.add(base, blend)

       Looks at the color information in each channel and adds the blend color to the base color.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.divide(base, blend)

       Looks at the color information in each channel and divides the base color with blend color.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN              • color (vmath.vector4)

cmath.subtract(base, blend)

       Looks at the color information in each channel and subtracts the blend color to the base color.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.color_dodge(base, blend)

       Brighter than the Screen blend mode. Results in an intense,
       contrasty color-typically results in saturated mid-tones and blown highlights.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.color_burn(base, blend)

       Darker than Multiply, with more highly saturated mid-tones and reduced highlights.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.linear_dodge(base, blend)

       Brighter than the Color Dodge blend mode, but less saturated and intense. (Same as cmath.add)

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

cmath.linear_burn(base, blend)

       Darker than Multiply, with more highly saturated mid-tones and reduced highlights.

       PARAMETERS
             • base (vmath.vector4) - The base color
             • blend (vmath.vector4) - The color that will be used for the blending

       RETURN
             • color (vmath.vector4)

harmony

Create complementary colors from your base color.

harmony.complementary(start_color)

       The complementary color is the color on the opposite side of the color wheel.

       PARAMETERS
             • start_color (vmath.vector4) - The color to generate from.

       RETURN
             • color (vmath.vector4)

harmony.monochromatic(start_color)

       Generate an Array of colors that are all the varieties of a single hue the
       tints, shades, and tones.

       PARAMETERS
             • start_color (vmath.vector4) - The color to generate from.

       RETURN
             • array (vmath.vector4) - Array of Vector4 colors of length count

harmony.analogous(start_color)

       An analogous color scheme involves three hues, all of which are positioned next
       to each other on the color wheel.

       PARAMETERS
             • start_color (vmath.vector4) - The color to generate from.

       RETURN
             • array (vmath.vector4) - The two colors that are analogous to the input.

harmony.split_complementary(start_color)

       Generate the two colors lying on either side of the start_color
       (the complementary) color.

       PARAMETERS
             • start_color (vmath.vector4) - The color to generate from.

       RETURN
             • array (vmath.vector4) - Array of the two complementary colors.

harmony.triadic(start_color)

       Generate the two colors that are triadic color.
       Triadic colors are equidistant on the color wheel.

       PARAMETERS
             • start_color (vmath.vector4) - The color to generate from.

       RETURN
             • array (vmath.vector4) - Array of the two colors to complement
                 the start_color to make a triadic color scheme.

harmony.tetradic(start_color)

       A tetrad is four colors, that is, two pairs of complementary combinations.

       PARAMETERS
             • start_color (vmath.vector4) - The color to generate from.

       RETURN
             • colors (table) - Array of the three colors to complement the
                 starting color to make a tetradic color scheme.

palette

Contains a few palettes (with made up named), they are between 5 and 10 colors.

palette.random()

       Returns a random palett

       PARAMETERS
             • None

       RETURN
             • colors (table) - Table containing (vmath.vector4) colors of the palett.
             • name (string) - Name of the generated palette.

palette.add(name, palette)

       Returns a random palett

       PARAMETERS
             • name (string) - Name of the generated palette.
             • palette (table) - Table containing (vmath.vector4) colors of the palett.

       RETURN
             • None

w3c

Named web colors.

About

Modify, transform and convert colors

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages