We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello,
I am trying to create an animation that cycles between three colors (orange, white, green) by fading in and out using the alpha channel. At this point I got it to work through one cycle using boolean statements, but then it just stops. How do I keep it cycling? Is there a way to do this without re-drawing the image each time, as I have in my code below:
PImage cat1;
PImage cat2;
float a;
float b;
float c;
float acc = 1;
boolean fadeinGreen = false;
boolean fadeinWhite = false;
boolean fadeinOrange = false;
boolean fadeOut = false;
void setup() {
fullScreen();
cat1 = loadImage("cat.png");
cat2 = loadImage(“cat2.png");
}
void draw() {
background(0);
noTint();
cat1.resize(width, 0);
image(cat1, 0, 50);
if (a < 255) {
fadeinGreen = true;
}
if (fadeinGreen == true) {
tint(0, 255, 0, a);
a = a + acc;
cat2.resize(width, 0);
image(cat2, 0, 50);
}
if (a == 255) {
fadeinWhite = true;
}
if (fadeinWhite == true) {
tint(255, b);
b = b + acc;
cat2.resize(width, 0);
image(cat2, 0, 50);
if (b == 255) {
fadeinOrange = true;
}
}
if (fadeinOrange == true) {
tint(255, 119, 0, c);
c = c + acc;
cat2.resize(width, 0);
image(cat2, 0, 50);
fadeOut = true;
}
if (fadeOut == true) {
if (c >= 255) {
acc = acc *-1;
}
if (c == 0) {
fadeOut = false;
fadeinGreen = true;
}
}
}
Answers
I didn't look at your code but this post is relevant: https://forum.processing.org/two/discussion/26558/fade-to-black-at-irregular-frequence-how-to-loop-on-the-last-fade#latest
kf
Thanks — I will check this out. I hadn't come across it before.
You have a smart quote in this code line that crashes the sketch -- and exposes a bug in the autoformatter.
How can we test this without the cat images -- can you say something about them (size -- or upload / link)? Does the sketch need these images to demonstrate your problem, or could it just use colored squares?
Should the fades all last the same duration?
The images are just black and white photos that are in the data folder. I want to just change the color using tint without having to re-draw them each time. The images are 2233 × 1596 px and I calling them from the data folder.
And yes, the fades should be the same duration.