A JSON of the top color palettes on ColourLovers.com for Processing. Inspired by nice-color-palettes.
Download the library from GitHub and install it in the sketchbook folder inside the folder name libraries. If you have any trouble you can read the official documentation.
Once you've installed the library, open Processing and import it into your sketch:
import nice.palettes.*;
Then you have to declare the main ColorPalette object.
ColorPalette palette;
In the void setup()
function initialize the object and pass a reference to the current PApplet
palette = new ColorPalette(this);
Now you can call the getPalette()
method to get an array of five different colors that work well together and are chosen randomly:
// Import the library
import nice.palettes.*;
// Declare the main ColorPalette object
ColorPalette palette;
void setup() {
// Initialize it, passing a reference to the current PApplet
palette = new ColorPalette(this);
// Get a random color palette
printArray(palette.getPalette());
}
void draw() {
}
You can recall a palette by passing a number to the method getPalette
. For example: getPalette(5)
will always return the same color palette.
// Import the library
import nice.palettes.*;
// Declare the main ColorPalette object
ColorPalette palette;
void setup() {
// Initialize it, passing a reference to the current PApplet
palette = new ColorPalette(this);
// Print an array of integers of the color palette
// Calling getPalette() with parameters will always return the same palette
printArray(palette.getPalette(5));
}
void draw() {
}
You can call the function getPaletteCount()
to have the numbers of available palettes
// Import the library
import nice.palettes.*;
// Declare the main ColorPalette object
ColorPalette palette;
void setup() {
// Initialize it, passing a reference to the current PApplet
palette = new ColorPalette(this);
palette.getPalette();
// Calling getPaletteCount() to return the number of palettes available
println(palette.getPaletteCount());
}
void draw() {
}
You can get the colors of a palette directly.
palette.colors[0];
Please remember that each palette array only contains five colors so palette.colors[5];
will return an error. If you wan to pick a random color inside the palette you can use this code:
palette.colors[(int)random(4)]
You can also assign the colors to a variable:
colors[] c = palette.getPalette();
printArray(c);
You can download an updated version of the top palettes on ColourLovers by calling the function refresh()
. The JSON file will be downloaded into the sketch's data folder and saved with the name nice-color-palettes.json.
palette.refresh();
By default the function refresh()
will download 20 results. But you use a parameter if you need more results (max 100) palette.refresh(100)
.