This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boolean approximates(ColorStop c, float tolerance) { | |
return abs(percent - c.percent) < tolerance; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
color evaluate(float percent) { | |
int sz = colors.size(); | |
if (sz == 0) { | |
return 0x00000000; | |
} | |
float diff; | |
float fraction; | |
ColorStop current; | |
ColorStop prev; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
size(512, 512); | |
background(0xffffffff); | |
noStroke(); | |
colorMode(HSB, 359, 99, 99); | |
ellipseMode(RADIUS); | |
textAlign(CENTER, CENTER); | |
int count = 16; | |
float centerX = width * 0.5; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int count = 16; | |
float w; | |
color[] palette; | |
void setup() { | |
size(512, 128); | |
noStroke(); | |
rectMode(CORNERS); | |
palette = genPalette(count, |