Scrappy Colour is a simple colour management library for Solar2D that allows for easy colour naming and access.
As with all my plugins it is free to use however if you find it useful, and are able to, I’d appreciate a coffee.
Image Credit: painting by ProSymbols from the Noun Project.
There are multiple ways to include the library in your project, the simplest is probably via the plugin, as outlined below, however if you wish you can also access the source code.
build.settings
settings = { plugins = { ["plugin.scrappyColour"] = { publisherId = "com.scrappyferret", supportedPlatforms = { iphone = { url="https://plugins.scrappyferret.com/scrappyColour/iphone.tgz" }, android = { url="https://plugins.scrappyferret.com/scrappyColour/android.tgz" }, macos = false, win32 = false }, }, }, }
main.lua
require( "plugin.scrappyColour" ) Scrappy.Colour:init()
If you wish you to access the source code directly it is available on GitLab here.
You can then clone or fork it if you wish, or add the library as a submodule to your project with this command:
git submodule add https://gitlab.com/scrappyferret-libs/scrappy-colour.git colour
However you get the source code into your project, you will then need to include it and initiate it.
main.lua
require( "colour.core" ) Scrappy.Colour:init()
Initiates the library.
Registers a named colour to the system.
name ( string ) – The name of the colour.
values ( table, or string ) – Indexed Table containing red, green, blue values. Alpha value optional, defaults to 1. Or it can be a string value containing the colour in hex format.
Gets a named colour from the system.
name ( string ) – The name of the colour.
palette ( string ) – The name of the palette. Optional, defaults to nil.
asTable ( boolean ) – True if you want the colours back as a table rather than multiple return values. Optional, defaults to false.
returns – The colour values, or as a table if desired.
Gets all named colours from the system.
palette ( string ) – The name of the palette if you’d just like those colours. Optional, defaults to nil.
returns – A list of colour names.
Creates a colour palette.
name ( string ) – The name for the palette.
returns – The name of the palette.
Adds a named colour to a palette.
palette ( string ) – The name for the palette.
name ( string ) – The palette-specific name of the colour.
colour ( string ) -The name of the colour that was originally added to the system.
Converts a hex string colour to r, g, b values.
hex ( string ) – The hex string.
returns – An indexed table containing the r, g, and b values.
Register and use a colour.
-- Register the colours Scrappy.Colour:register( "player1", "#0892D0" ) Scrappy.Colour:register( "player2", { 1, 0, 0 } ) -- Create some "players" local player1 = display.newRect( 100, 100, 50, 50 ) player1:setFillColor( Scrappy.Colour:get( "player1" ) ) local player2 = display.newRect( 200, 100, 50, 50 ) player2:setFillColor( Scrappy.Colour:get( "player2" ) )