Colors Library (ssk.colors.*)
Easy Colors (ssk.colors.easy.*)
_WHITE_ , _W_ |
_BLACK_ , _K_ |
_TRANSPARENT_ , _T_ |
_RED_ , _R_ |
_GREEN_ , _G_ |
_BLUE_ , _B_ |
_LIGHTGREY_ |
_GREY_ |
_DARKGREY_ |
_CYAN_ , _C_ |
_YELLOW_ , _Y_ |
_ORANGE_ , _O_ |
_PURPLE_ |
_PINK_ , _P_ |
local circ = display.newCircle( 100, 100, 100 )
rect:setFillColor( unpack( _PURPLE_ ) )
Color Helpers and Utilities (ssk.colors.*)
Tip: These functions are exported as globals when SSK init()
parameter exportColors
is true
.
hexcolor( code )
- converts hex color codes to rgba Graphics 2.0 valuerandomColor( )
- Returns random color selected from 'Easy Colors'.rgba2( colors )
- Converts Graphics 1.0 color table to a valid Graphics 2.0 color table.
local rect1 = display.newRect( 100, 100, 100, 100 )
local rect2 = display.newRect( 100, 100, 200, 100 )
local rect3 = display.newRect( 100, 100, 300, 100 )
-- Set fill color to a nice blue
rect1:setFillColor( unpack( hexcolor( "33AFFF" ) ) )
-- Choose a random Easy Color as the fill
rect2:setFillColor( unpack( randomColor() ) )
-- Set color to Graphics 1.0 encoded 'Pink'
rect3:setFillColor( unpack( rgba2( { 255, 0, 255 } ) ) )
RGB
- R - Red component in the range [0,1].
- G - Green component in the range [0,1].
- B - Blue component in the range [0,1].
- A - Alpha in the range [0,1]. Assumed to be 1 if not specified.
(Graphcs 1.0 used values in the range [0,255].)
local lightGrey = { 0.25, 0.25, 0.25, 1 }
RGB Functions (ssk.colors.*)
Tip: These functions are NOT exported and can only be accessed via ssk.colors.*
or localizations.
rgb2hsl( r, g, b, a )
- Convert RGB color to HSL color table.mixRGB( c1, c2 )
- Evenly mix two RGBa colors.randomRGB( [ c1 ] )
- Generates a random RGB color. If optional c1 is passed in, it is mixed evenly with the random color.pastelRGB( [ c1 ] )
- Generates a random RGB pastel color. If optional c1 is passed in, it is mixed evenly with the random color.rgbOffset( r, g, b, a, angle )
- Converts RGB color to HSL and applies hueOffset()rgbNeighbors( r, g, b, a, angle )
- Converts RGB color to HSL and applies hslNeighbors(), then returns two rgb colors.rgbTriadic( r, g, b, a )
- Converts RGB color to HSL and applies hslTriadic(), then returns two rgb colors.rgbSplitComplementary( r, g, b, a, angle )
- Converts RGB color to HSL and applies hslSplitComplementary(), then returns two rgb colors.
HSL
- H - Hue is a degree on the color wheel in the range [0,360).
- 0 is red, 120 is green, 240 is blue.
- Numbers in between reflect different shades.
- S - Saturation is a percentage value in the range [0,1].
- 1.0 is the full color.
- L - Lightness is also a percentage value in the range [0,1].
- 0.0 is dark (black),
- 1.0 1.0 is light (white)
- 0.5 is the average
- A - Alpha in the range [0,1]. Assumed to be 1 if not specified.
local cornFlowerBlue = hsl2rgb( 219, 0.79, 0.66, 1.0 )
HSL Functions (ssk.colors.*)
Tip: These functions are NOT exported and can only be accessed via ssk.colors.*
or localizations.
hsl2rgb( h, s, l, a )
- Convert HSL color to RGB color table.hueOffset( h, s, l, a, angle )
- Rotate hue by 'angle' degreeshslNeighbors( h, s, l, a, angle )
- Return two arbitray angle neighbors (left and right by angle)hslTriadic( h, s, l, a )
- Return two triadic neighbors of colorhslSplitComplementary( h, s, l, a, angle )
- Return two complementary split angle colors.
Examples
RGB & HSL
function test.run( group, params )
group = group or display.currentStage
params = params or {}
local startX = left + 100
local startY = top + 100
local curX = startX
local curY = startY
-- ==============================================
-- Row 1 - Test conversions
-- ==============================================
-- RGB 2 HSL & HSL 2 RGB
curX = startX
local c = ssk.colors.rgb2hsl(_R_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_G_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_B_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_O_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_Y_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_P_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_PURPLE_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_GREY_)
local c2 = ssk.colors.hsl2rgb( c )
newRect( group, curX, curY, { size = 80, fill = c2 } )
-- ==============================================
-- Row 2 - Test HSL HUE Offset
-- ==============================================
-- hueOffset
curX = startX
curY = curY + 100
local c = ssk.colors.rgb2hsl(_R_)
local c1 = ssk.colors.hueOffset(c, 60 )
local c2 = ssk.colors.hsl2rgb( c1 )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
local c = ssk.colors.rgb2hsl(_R_)
local c1 = ssk.colors.hueOffset(c, -60 )
local c2 = ssk.colors.hsl2rgb( c1 )
newRect( group, curX, curY, { size = 80, fill = c2 } )
-- ==============================================
-- Row 3 - Test HSL Neighbors, Triadic, Split Complementary
-- ==============================================
-- hslNeighbors
curX = startX
curY = curY + 100
local c = ssk.colors.rgb2hsl(_R_)
local c2,c3 = ssk.colors.hslNeighbors( c, 90 )
c2 = ssk.colors.hsl2rgb( c2 )
c3 = ssk.colors.hsl2rgb( c3 )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = c3 } )
-- hslTriadic
curX = curX + 100
local c = ssk.colors.rgb2hsl(_R_)
local c2,c3 = ssk.colors.hslTriadic( c )
c2 = ssk.colors.hsl2rgb( c2 )
c3 = ssk.colors.hsl2rgb( c3 )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = c3 } )
-- hslSplitComplementary
curX = curX + 100
local c = ssk.colors.rgb2hsl(_R_)
local c2,c3 = ssk.colors.hslSplitComplementary( c, 30 )
c2 = ssk.colors.hsl2rgb( c2 )
c3 = ssk.colors.hsl2rgb( c3 )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = c3 } )
-- ==============================================
-- Row 4 - Test RGB Offset
-- ==============================================
-- rgbOffset
curX = startX
curY = curY + 100
local c1 = ssk.colors.rgbOffset( _R_, 60 )
newRect( group, curX, curY, { size = 80, fill = c1 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
local c1 = ssk.colors.rgbOffset( _R_, -60 )
newRect( group, curX, curY, { size = 80, fill = c1 } )
-- ==============================================
-- Row 5 - Test RGB Neighbors, Triadic, Split Complementary
-- ==============================================
-- hslNeighbors
curX = startX
curY = curY + 100
local c2,c3 = ssk.colors.rgbNeighbors( _R_, 90 )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = c3 } )
-- rgbTriadic
curX = curX + 100
local c2,c3 = ssk.colors.rgbTriadic( _R_ )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = c3 } )
-- rgbSplitComplementary
curX = curX + 100
local c2,c3 = ssk.colors.rgbSplitComplementary( _R_, 30 )
newRect( group, curX, curY, { size = 80, fill = c2 } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = _R_ } )
curX = curX + 80
newRect( group, curX, curY, { size = 80, fill = c3 } )
end
Pastels
function test.run( group, params )
group = group or display.currentStage
params = params or {}
local startX = left + 100
local startY = top + 100
local curX = startX
local curY = startY
-- Pastel No Seed Color
for i = 1, 3 do
curX = startX
for j = 1, 10 do
newRect( group, curX, curY, { size = 80, fill = ssk.colors.pastelRGB( ) } )
curX = curX + 80
end
curY = curY + 80
end
curY = curY + 40
-- Pastel Random Seed Color
for i = 1, 3 do
curX = startX
for j = 1, 10 do
newRect( group, curX, curY, { size = 80, fill = ssk.colors.pastelRGB( randomColor() ) } )
curX = curX + 80
end
curY = curY + 80
end
end
Copyright © Roaming Gamer, LLC. 2008-2016; All Rights Reserved