Random Color Palettes with colorLib
Posted on 2011-04-13 by Jan Vantomme
Tags:
processing, colorlib, tutorial
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.
RandomPalette p;
Inside 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.
p.randomSwatches();
Adding Colors
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
p.addRandomColor();
// add two colors to the end of the Palette
p.addRandomColors(2);
Downloads
You can download the example for the RandomPalette right here from the blog. colorLib v1.0 is available from Google Code.