If I got it right, opacity means that alpha argument for color and, by hit 100 opacity and back to 30, you meant bouncing between that range, right?
Well, I was doing an ellipse bounce animation sample for another thread. So, why not include an opacity bouncing as well?
Hope it can help you somehow:
- //
- // Ellipse Bouncing Animation Sample (v1.5)
- // by GoToLoop (2012/Oct)
- //
- // https://forum.processing.org/topic/using-arrays-to-create-and-change-circles
- // https://forum.processing.org/topic/opacity-loop
- //
- private static final byte ellipseTotal = 3;
- private static final MyEllipse[] my = new MyEllipse[ellipseTotal];
- final void setup() {
- size (500, 500);
- frameRate(60);
- smooth();
- noStroke();
- my[0] = new MyEllipse(
- 120, 70, // initX, initY
- 50, 40, // sizeX, sizeY
- 7, 3, // movX, movY
- #0000FF, 30, 4); // colour, opacity, opacIncrease
- my[1] = new MyEllipse(
- 320, 400, // initX, initY
- 40, 50, // sizeX, sizeY
- 3, 7, // movX, movY
- #00FF00, 100, -5); // colour, opacity, opacIncrease
- my[2] = new MyEllipse(
- 250, 250, // initX, initY
- 30, 30, // sizeX, sizeY
- -7, 4, // movX, movY
- #FF0000, 50, 1); // colour, opacity, opacIncrease
- }
- final void draw() {
- background(0);
- // for ( byte index=0; index<ellipseTotal ; my[index++].everything() );
- for ( MyEllipse ellip : my ) ellip.everything();
- }
- private final class MyEllipse {
- short x, y;
- byte szX, szY;
- byte mvX, mvY;
- color cor;
- short opac;
- byte oInc;
- private static final short oMin = 30, oMax = 100;
- MyEllipse (
- int initX, int initY,
- int sizeX, int sizeY,
- int movX, int movY,
- color colour, int opacity, int opacIncrease) {
- x = (short) initX;
- y = (short) initY;
- szX = (byte) sizeX;
- szY = (byte) sizeY;
- mvX = (byte) movX;
- mvY = (byte) movY;
- cor = colour;
- opac = (short) opacity;
- oInc = (byte) opacIncrease;
- }
- private final void everything() {
- update();
- opacity();
- display();
- }
- private final void update() {
- x += mvX;
- y += mvY;
- if (x < 0 || x > width) mvX *= -1;
- if (y < 0 || y > height) mvY *= -1;
- }
- private final void opacity() {
- if (opac < oMin || opac > oMax) oInc *= -1;
- opac += oInc;
- }
- private final void display() {
- fill(cor, opac);
- ellipse(x, y, szX, szY);
- }
- }