Skip to content

Instantly share code, notes, and snippets.

@behreajj
Created June 25, 2017 17:43
Show Gist options
  • Save behreajj/45d7df56d547f1a99f8f2c11263013f8 to your computer and use it in GitHub Desktop.
Save behreajj/45d7df56d547f1a99f8f2c11263013f8 to your computer and use it in GitHub Desktop.
Color Gradients 2-11
int count = 16;
float w;
color[] palette;
void setup() {
size(512, 128);
noStroke();
rectMode(CORNERS);
palette = genPalette(count,
10, 180, 270,
99, 69,
69, 99);
w = width / float(count);
}
void draw() {
for (int i = 0; i < count; ++i) {
fill(palette[i]);
rect(i * w, 0, (i + 1) * w, height);
}
}
color[] genPalette(int colorCount,
int hueOffset, int hueMin, int hueMax,
int satMin, int satMax,
int briMin, int briMax) {
color[] result = new color[colorCount];
float hue = random(hueMin, hueMax);
float percent;
pushStyle();
colorMode(HSB, 359, 99, 99);
for (int j = 0; j < colorCount; ++j) {
percent = j / float(colorCount - 1);
result[j] = color((hue + j * hueOffset) % 360,
lerp(satMin, satMax, percent),
lerp(briMin, briMax, percent));
}
popStyle();
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment