Scrappy Colour is a simple helper library for Solar2D for working with colours.
A full API listing can be found here.
Register and use a colour.
-- Load plugin library
require "plugin.scrappyColour"
-- Initiate the library
Scrappy.Colour:init()
-- Register a colour and call it 'player1'
Scrappy.Colour:register( "player1", { 0, 1, 0 } )
-- Register a colour and call it 'player2'
Scrappy.Colour:register( "player2", "D30F6F" )
-- Create a player object with the first colour
local player1 = display.newCircle( 100, 100, 10 )
player1:setFillColor( Scrappy.Colour:get( "player1" ) )
-- Create a player object with the second colour, this time retrieving it as a table
local player2 = display.newCircle( 200, 100, 10 )
local colour = Scrappy.Colour:get( "player2", nil, true )
player2:setFillColor( colour[ 1 ], colour[ 2 ], colour[ 3 ] )
Convert a hex colour to rgb values.
-- Get the values
local rgb = Scrappy.Colour:hexToRGB( "D30F6F" )
-- Print them out
print( rgb[ 1 ], rgb[ 2 ], rgb[ 3 ] )
Get a list of registered colours.
-- Get a list of all registered colours
local registered = Scrappy.Colour:list()
-- And loop through them
for k, v in pairs( registered ) do
-- Printing out their names and values
print( k, v[ 1 ], v[ 2 ], v[ 3 ] )
end
Trusted vendor
Log in now to purchase this plugin from Scrappy Ferret.
Once you've activated this plugin, appropriate build.settings code will be generated for you to copy into your Solar2D project. Download links will also be available for inclusion into a Solar2D Native project.