Skip to content

Instantly share code, notes, and snippets.

@behreajj
behreajj / clrGrad_2_2.pde
Created June 25, 2017 16:46
Color Gradients 2-2
class Gradient {
ArrayList<ColorStop> colors = new ArrayList<ColorStop>();
Gradient() {
}
Gradient(ColorStop... cs) {
for (int i = 0, sz = cs.length; i < sz; ++i) {
colors.add(cs[i]);
}
@behreajj
behreajj / clrGrad_2_3.pde
Last active June 25, 2017 16:47
Color Gradients 2-3
boolean approximates(ColorStop c, float tolerance) {
return abs(percent - c.percent) < tolerance;
}
@behreajj
behreajj / clrGrad_2_4.pde
Last active June 25, 2017 16:53
Color Gradients 2-4
void addColorStop(ColorStop cs) {
ColorStop other;
for (int i = 0, sz = colors.size(); i < sz; ++i) {
other = colors.get(i);
if (cs.approximates(other, Gradient.TOLERANCE)) {
println(cs, "percentage is too close to", other);
return;
}
}
colors.add(cs);
@behreajj
behreajj / clrGrad_2_5.pde
Last active June 25, 2017 17:17
Color Gradients 2-5
Gradient(ColorStop... cs) {
int sz = cs.length;
for (int i = 0; i < sz; ++i) {
colors.add(cs[i]);
}
if (sz > 1) {
java.util.Collections.sort(colors);
removeDuplicates();
}
}
@behreajj
behreajj / clrGrad_2_6.pde
Created June 25, 2017 17:18
Color Gradients 2-6
color evaluate(float percent) {
int sz = colors.size();
if (sz == 0) {
return 0x00000000;
}
float diff;
float fraction;
ColorStop current;
ColorStop prev;
@behreajj
behreajj / clrGrad_2_7.pde
Created June 25, 2017 17:21
Color Gradients 2-7
Gradient grad;
float fw;
void setup() {
size(1024, 128);
fw = float(width);
grad = new Gradient(
new ColorStop(0.75, 0xffff007f),
new ColorStop(0.333, 0xff7f00ff),
new ColorStop(0.5, 0xff00ff00),
@behreajj
behreajj / clrGrad_2_8.pde
Created June 25, 2017 17:22
Color Gradients 2-8
colorMode(HSB, 359, 99, 99);
grad = new Gradient(new ColorStop(0, color(29, 99, 99)),
new ColorStop(0.33, color(329, 99, 99)),
new ColorStop(0.66, color(89, 99, 99)),
new ColorStop(1, color(269, 99, 99)));
@behreajj
behreajj / clrGrad_2_9.pde
Created June 25, 2017 17:31
Color Gradients 2-9
size(512, 512);
background(0xffffffff);
noStroke();
colorMode(HSB, 359, 99, 99);
ellipseMode(RADIUS);
textAlign(CENTER, CENTER);
int count = 16;
float centerX = width * 0.5;
@behreajj
behreajj / clrGrad_2_10.pde
Created June 25, 2017 17:39
Color Gradients 2-10
size(600, 200);
rectMode(CORNERS);
ellipseMode(RADIUS);
noStroke();
int[] blendModes = { BLEND, ADD, SUBTRACT };
// Red, Green, Blue, Cyan, Magenta, Yellow
color[] palette = { 0x55ff0000, 0x5500ff00,
0x550000ff, 0x5500ffff, 0x55ff00ff,
@behreajj
behreajj / clrGrad_2_11.pde
Created June 25, 2017 17:43
Color Gradients 2-11
int count = 16;
float w;
color[] palette;
void setup() {
size(512, 128);
noStroke();
rectMode(CORNERS);
palette = genPalette(count,