Trail effect on waterfall issue

Hi all! I’m trying to implement a simple waterfall sketch, but I’m having an issue with how to show a trail effect on my drops object while moving acros the screen. Here is my code:

import java.util.List;
import java.util.Iterator;

int DROPS_PER_FRAME = 10;
float DROP_RADIUS = 5;
float GRAVITY = 1;
float FRICTION = 0.1;
float X_OSCILLATION = 1;
float EXP_RADIUS = 250;
float EXP_POWER = 100;
float WIND_FRICTION = 0.005;
float WIND_MARGIN_LIMIT = 0.25;

List<Drop> drops;
float xWind;

void setup () {
  fullScreen();
  drops = new ArrayList<Drop>();
  xWind = width/2;
}


void draw () {
  background(0, 0, 0, 100);
  rain();
  drops();  
}

void rain () {
  
  for(int i=0; i < DROPS_PER_FRAME; i++)
    drops.add(new Drop(random(-2*width, 4*width), 0));
  
  Iterator<Drop> d = drops.iterator();
  while(d.hasNext()) {
    if(d.next().isOffscreen())
      d.remove();
  }
}

void drops () {
  for(Drop d : drops) {
    d.move();
    d.show();
  }
}

////////


class Drop {
  
  float x, y;
  float xSpeed, ySpeed;
  int R,G,B;
  
  Drop(float x, float y) {
    
    this.x = x;
    this.y = y;
    this.xSpeed = 0;
    this.ySpeed = 0;
    this.R = int(random(50));
    this.G = int(random(255));
    this.B = 255;
    
  }
  
  void show () {
    noStroke();
    fill(this.R, this.G, this.B);
    ellipse(this.x, this.y, DROP_RADIUS*2, DROP_RADIUS*2);  
  }
  
  void move () {
    
    this.xSpeed += random(-X_OSCILLATION, X_OSCILLATION);
    this.ySpeed += GRAVITY;  
    
    this.x += this.xSpeed * FRICTION;
    this.y += this.ySpeed * FRICTION;
    
  }
  
  boolean isOffscreen () {
    return this.y - DROP_RADIUS > height; 
  }
  
  
}

I put a bit of alpha in the backgound funcion background(0, 0, 0, 100), what I expected to happen was that every frame is adding a layer of black on the screen, and with the drops keep moving I was expecting a trail effect of every drop that disappear after a bit, but nothing is happening.
What have I done wrong?

Thank you!

1 Like

Hmm. That’s weird, it should do the trailing thing but it doesn’t.
However, replacing background(0, 0, 0, 100); with fill(0, 100); rect(0,0,width,height); - which should do exactly the same thing - does a different thing, and does exactly what you want. So, you might want to use that instead.

Also it has a performance impact, too. I suggest using fullScreen(P2D); instead, as that’s usually faster.

2 Likes