Color change logic
in
Programming Questions
•
1 year ago
I'm working on a way to make a javaScript color changer and I'm using Processing for testing because it is easy to test out logic fast. I would like to make a color changer that just uses if statements with basic data types (boolean, int) so that it is easy to use cross language (so that means no hue() or anything). So far I have the code below which isn't too bad for what I have in mind but seems to miss a few colors (like green most notably). Does anyone know of a nice way to set up a color changer that avoids white / gray / black and hits all of the hues?
NOTE: Heads up for EPILEPSY if you are sensitive to it! I set the speed to be fairly slow but heads up anyway, I don't know too much about the condition but I know that flashing lights can be bad for it.
int speed = 5;
boolean[] cGo = new boolean[3];
boolean[] cDir = new boolean[3];
int[] channel = new int[3];
void setup() {
size(400, 400);
for (int i = 0; i < 3; i++) cDir[i] = true;
cGo[0] = true;
}
void draw() {
for (int i = 0; i < 3; i++) {
if (cGo[i]) {
if (cDir[i]) channel[i] += speed;
else channel[i] -= speed;
if (channel[i] <= 0) {
channel[i] = 0;
cDir[i] = !cDir[i];
}
if (channel[i] >= 255) {
channel[i] = 255;
cDir[i] = !cDir[i];
}
if (i < 2 && channel[i] > 128) cGo[i+1] = true;
}
}
background(channel[0], channel[1], channel[2]);
}
1