I have written code in which the stroke color should transition smoothly through red, orange, yellow, green etc. in a loop. The rest of the code works perfectly but I am having issues attaining the color transitions.
It’s expected that the Red value increases by 1 until it reaches 255, where it stays as the Green value does the same. Then the Red value should begin the decrease by 1 whilst the Green remains at 255.
The issue with the code is that the Red and Green values will both increase as necessary, but no matter what I try, I can’t get the Red value to decrease.
Any input will be greatly appreciated. Please note I believe the issues lie in the code block at the end after the line marked //color transitions. I have also posted this question on Stack Overflow here: How to debug smooth color change in processing? - Stack Overflow
float angNoise, radiusNoise;
float xNoise, yNoise;
float angle = -PI/2;
float radius;
int red = 0;
int blue = 0;
int green = 0;
int redValue = 1;
int greenValue = 1;
int blueValue = 1;
int colorMode = 1;
void setup(){
size(800, 600);
smooth();
frameRate(24);
background(0);
noFill();
angNoise = random(10);
radiusNoise = random(10);
xNoise = random(10);
yNoise = random(10);
}
void draw(){
radiusNoise += 0.005;
radius = (noise(radiusNoise)*550)+1;
angNoise += 0.005;
angle += (noise(angNoise)*6)-3;
if(angle > 360){ angle -= 360; }
if(angle < 0){ angle += 360; }
xNoise += 0.01;
yNoise += 0.01;
float centerX = width/2 +(noise(xNoise)*100)-50;
float centerY = height/2 +(noise(yNoise)*100)-50;
float rad = radians(angle);
float x1 = centerX + (radius*cos(rad));
float y1 = centerY + (radius*sin(rad));
float opprad = rad + PI;
float x2 = centerX + (radius*cos(opprad));
float y2 = centerY + (radius*sin(opprad));
//color transitions
stroke(red, green, blue); //60);
strokeWeight(2);
ellipse(x1, y1, x2, y2);
//color mode 1 (red)
if (colorMode == 1){blueValue = -1;
if (red == 255 && blue == 0) {colorMode++;}
if (red == 0) {redValue = +1;}
red += redValue;}
//color mode 2 (green)
if (colorMode == 2){redValue = -1;
if (green == 255 && red == 0) {colorMode++;}
if (green == 0) {greenValue = +1;}
green += greenValue;}
//color mode 3 (blue)
if (colorMode == 3){greenValue = -1;
if (blue == 255 && green == 0) {colorMode++;}
if (blue == 0) {blueValue = +1;}
blue += blueValue;}
if (colorMode > 3) {colorMode =1;}
}