Random Color Palettes with colorLib
I’ve just released colorLib v1.0 today. The new version has some bug fixes, better documentation and a new RandomPalette class. In this short tutorial, I’m going to show you how to use this class.
The first thing you need to do is to declare a RandomPalette object, right before the
setup() function, you need to call the
RandomPalette() constructor to actually create the object. There are two constructors available. The standard one creates a Palette with 5 random swatches, the second one lets you choose how many swatches you want.
// generate a Palette with 5 random colors
p = new RandomPalette(this);
// generate a Palette with 7 random colors
p = new RandomPalette(this, 7);
Regenerate the Palette
If you are not happy with the random colors, there is a method to regenerate the Palette. You can call the
randomSwatches() method and a new Palette will be generated.
There are two methods to add extra random colors to the Palette:
addRandomColor() adds one color to the end of the Palette,
addRandomColors(int numSwatches) lets you decide how many colors you want to add.
// add one color to the end of the Palette
// add two colors to the end of the Palette