Skip to content

Instantly share code, notes, and snippets.

@behreajj
behreajj / clrGrad_1_1.pde
Created June 25, 2017 14:48
Color Gradients 1-1
color red = 0xffff0000;
println(red);
println(hex(red));
@behreajj
behreajj / clrGrad_1_7.pde
Created June 25, 2017 15:25
Color Gradients 1-7
size(512, 256);
loadPixels();
int len = pixels.length;
float h = float(height);
float w = float(width);
float diamonds = TWO_PI * 8;
float red;
float green;
@behreajj
behreajj / clrGrad_1_8.pde
Created June 25, 2017 15:50
Color Gradients 1-8
PImage bkg;
color px;
float centerX;
float centerY;
float run;
float rise;
float distSq;
float invDist;
@behreajj
behreajj / clrGrad_1_9.pde
Created June 25, 2017 16:02
Color Gradients 1-9
size(512, 256, P2D);
color start = 0xff00ffff;
color stop = 0xffff00ff;
color clear = 0x00ffff00;
float count = 64;
float centerX = width * 0.5;
float centerY = height * 0.5;
float stopRad = max(centerX, centerY) - 2.5;
@behreajj
behreajj / clrGrad_2_1.pde
Created June 25, 2017 16:40
Color Gradients 2-1
class ColorStop implements Comparable<ColorStop> {
float percent;
color clr;
ColorStop(float prc, float v1, float v2, float v3) {
this(prc, color(v1, v2, v3));
}
ColorStop(float prc, float v1, float v2, float v3, float al) {
this(prc, color(v1, v2, v3, al));
@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;