Created
March 25, 2016 00:00
-
-
Save jacobjoaquin/68691be255393c9e7000 to your computer and use it in GitHub Desktop.
Class for doing custom gradients / color wheels
This file contains 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 captureFrames = false; | |
int nFrames = 120; | |
float phase = 0.0; | |
float phaseInc = 1 / (float) nFrames; | |
MetaPalette mp; | |
int nStrips = 40; | |
int ledsPerStrip = 32 * 5; | |
class MetaPalette { | |
ArrayList<Integer> colors; | |
MetaPalette() { | |
colors = new ArrayList<Integer>(); | |
} | |
void add(color c) { | |
colors.add(c); | |
} | |
color get(float p) { | |
int s = colors.size() - 1; | |
p *= s; | |
color c1 = colors.get(floor(p)); | |
color c2 = colors.get(ceil(p)); | |
float interp = (p - floor(p)); | |
return lerpColor(c1, c2, interp); | |
} | |
} | |
void settings() { | |
size(500, 500, P2D); | |
} | |
void setup() { | |
mp = new MetaPalette(); | |
mp.add(color(255)); | |
mp.add(color(255, 128, 0)); | |
mp.add(color(255, 0, 128)); | |
mp.add(color(0)); | |
mp.add(color(255, 0, 255)); | |
mp.add(color(255)); | |
mp.add(color(255, 128, 0)); | |
mp.add(color(255, 0, 128)); | |
mp.add(color(0)); | |
mp.add(color(255, 0, 255)); | |
mp.add(color(255)); | |
noStroke(); | |
blendMode(ADD); | |
} | |
void draw() { | |
background(0); | |
float thisPhase = phase; | |
float stripLength = 250; // Units in screen pixels | |
pushMatrix(); | |
translate(width / 2.0, height / 2.0); | |
for (int i = 0; i < nStrips; i++) { | |
float n = i / (float) nStrips; | |
float angle = n * TAU; | |
PVector p = PVector.fromAngle(angle); | |
for (int j = 0; j < stripLength; j++) { | |
PVector p2 = p.copy().mult(j); | |
fill(mp.get(thisPhase)); | |
ellipse(p2.x, p2.y, 2, 2); | |
thisPhase += phaseInc; | |
thisPhase -= (int) thisPhase; | |
} | |
} | |
popMatrix(); | |
phase += phaseInc; | |
phase -= (int) phase; | |
if (captureFrames) { | |
saveFrame("./gif/f######.gif"); | |
if (frameCount == nFrames) { | |
exit(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment