Greetings! I made a github repo for a color tool I made and use in my projects to be primarily used with the setColor() function. I originally made it to create simple tiled lighting effects but I also use it to store colors by name (e.g. All enemies should be 'red, while allies are 'blue'). The best features though are the color mixing tools; there are two: mix() and gradient(). The first mixes two colors while the latter will interpolate between 2-4 colors based on a distance/range. There are also RGB clamp settings that are applied with mix() and gradient().
Here is some sample code:
Code: Select all
Spectra = require('spectra')
spectra = Spectra()
--Init with default palette
spectra:edit('enemy', spectra:get('red'))
love.graphics.setColor( spectra:get('enemy', 128) )
--The color has been set to enemy(red) with half opacity
love.graphics.setColor ( spectra:mix('purple', 255, 300, 'green', .5) )
--The color has been set to a purple/green mix with increased brightness
love.graphics.setColor( spectra:gradient(512, 256, {'aqua','blue','midnight','black'}))
--The color has been set to midway between 'blue' and 'midnight' in the gradient and
--will interpolate between all four colors based on distance
spectra:clamp('darkgray', .5, 'lightblue', .25)
--A 50% darkgray minimum color has been applied
--A 25% lightblue maximum color has been applied
Please forgive if this is confusing; a better explanation exists on the github repo. I have also attached a functional demo. Also, please feel free to give me feedback; I'm still learning!
Spectra Color Manager Github Repo