Scrappy Colour

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.

Getting Started

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.



settings =
    plugins =
        ["plugin.scrappyColour"] =
            publisherId = "com.scrappyferret",
            supportedPlatforms =
                iphone = { url="" },
                android = { url="" },
                macos = false,
                win32 = false


require( "plugin.scrappyColour" )


Source Code

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 colour

However you get the source code into your project, you will then need to include it and initiate it.


require( "colour.core" )




Initiates the library.

Scrappy.Colour:register( name, values )

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.

Scrappy.Colour:get( name, palette, asTable )

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.

Scrappy.Colour:list( palette )

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.

Scrappy.Colour:createPalette( name )

Creates a colour palette.

name ( string ) – The name for the palette.

returns – The name of the palette.

Scrappy.Colour:addToPalette( palette, name, colour )

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.

Scrappy.Colour:hexToRGB( hex )

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" ) )