Skip to content
Jan Vantomme edited this page Aug 29, 2014 · 1 revision

A Palette is an object that stores multiple Swatches. The most basic way to create a Palette is to feed a color array into the constructor.

color[] colors = new color[ 4 ];
colors[0] = color( 255, 0, 0 );
colors[1] = color( 0, 255, 0 );
colors[2] = color( 0, 0, 255 );
colors[3] = color( 255, 255, 0 );
	
p = new Palette( this, colors );

To draw the Palette, you can use the drawSwatches() method. If you add the width and height parameters to the method, you can draw them at the size you want.

p.drawSwatches();
p.drawSwatches( 180, 60 );

This is the full code for the sketch, you can also find it in the examples folder that comes with the colorLib download.

import colorlib.webservices.*;
import colorlib.tools.*;
import colorlib.*;

Palette p;

void setup()
{
	size( 200, 200 );
	smooth();
	noStroke();
	
	color[] colors = new color[ 4 ];
	colors[0] = color( 255, 0, 0 );
	colors[1] = color( 0, 255, 0 );
	colors[2] = color( 0, 0, 255 );
	colors[3] = color( 255, 255, 0 );
	
	p = new Palette( this, colors );
}

void draw()
{
	background( 0 );
	translate( 10, 10 );
	p.drawSwatches();
	
	translate( 0, 50 );
	p.drawSwatches( 180, 60 );
}

If you run the code, you should get to see a the same Palette twice, but drawn with a different size. Just like in the image below.

Screenshot of the Palette example

Clone this wiki locally