Cycle between three colors using alpha channel

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

Sign In or Register to comment.