2D Colour Animation
in
Programming Questions
•
5 months ago
This is a simple exercise in getting to grips with colour values and animation in Processing. I'm trying to figure out how to create colour tweens, without the use of a library. I was hoping to apply this to some animation e.g. such as a changing background for an animation. So far this is what I have, it's pretty messy, and only uses if statements to change colour values. I had to look at colour value changes on an RGB scale to get the difference in values.
There's a bit of lag between
green and
cyan. The green values don't decrease immediately when the if statements called. I put in a print statement to check the values, but they seem to stick at 255 for while before decreasing.
If anyone can offer any help pointers, or advice for a better method to do this, with the exception of using libraries, it would be much appreciated; thanks
P.S. Can this be done with for loops?
//Colour tween animation
//Set starting colour values
int r = 255;
int g = 0;
int b = 0;
//Control rate of colour change
int speed = 4;
void setup() {
size(400, 400);
}
void draw() {
//Assign int values to background
background(r, g, b);
//Start, increase green RGB value
//Red to yellow
g = g + 1;
//Yellow to green
if(g >= 255) {
g = 255;
r = r - speed;
}
//Green to cyan
if( r <= 0) {
r = 0;
b = b + speed; //lag between change
println("green: " + g);
}
//cyan to blue
if(b >= 255){
b = 255;
g = g - speed;
}
//Blue to purple
if(g <= 0){
g = 0;
r = r + speed;
}
//Purple to read
if(r >= 255){
r = 255;
b = b - speed;
}
}
//Set starting colour values
int r = 255;
int g = 0;
int b = 0;
//Control rate of colour change
int speed = 4;
void setup() {
size(400, 400);
}
void draw() {
//Assign int values to background
background(r, g, b);
//Start, increase green RGB value
//Red to yellow
g = g + 1;
//Yellow to green
if(g >= 255) {
g = 255;
r = r - speed;
}
//Green to cyan
if( r <= 0) {
r = 0;
b = b + speed; //lag between change
println("green: " + g);
}
//cyan to blue
if(b >= 255){
b = 255;
g = g - speed;
}
//Blue to purple
if(g <= 0){
g = 0;
r = r + speed;
}
//Purple to read
if(r >= 255){
r = 255;
b = b - speed;
}
}
1