Random ellipses fading in

Hi!

I’m having troubel combining two codes. I’d like to have ellipses fade in and then dissappear again.
Thanks in advance!

Code 1; (does the job OK but fades out.

void setup() {
  size(1920,1080);
  //size(3840,2160);
  frameRate(25);
  background(0);
  noStroke();
}

void draw(){
  fill(0,10);
  rect(0,0, width, height);
  fill(255);
  ellipse(random(width), random(height),4,4);
}

Code 2 (when I try more than one ellipse it doesn’t fade anymore)

void setup(){
  size(1920,1080);
  //(3840,2160);
  background(0);
frameRate(25);
  noStroke();

}
 
void draw(){
background(0); 
  fill(255,0+map(millis()%3000,0,3000,0,300));
 //ellipse(random(width), random(height),4,4);
ellipse(width/2,height/2,4,4);
}
1 Like

Hi. You can edit and format your code by selecting the text and tapping </>
I think the problem with your second code is because you are using background(0) which does not fade like

  fill(0,10);
  rect(0,0,width,height);

Mmmm I’m not sure about what you want

fill(); affects to all the following lanes of your code till you change it to other configuration, just add more ellipses and they will act all in same mode:

void draw(){
  background(0);
  fill(255,0+map(millis()%3000,0,3000,0,300));
  for(int i=0;i < width; i+=50){
    for(int j=0;j < height; j+=50){
       ellipse(i, j,40,40);
    }
  }
}

In the first example the fade out happens because you are adding more transparent black layers and when you add transparent layers over and over, your layer will get to that color, hiding the ellipses drawn.

2 Likes

I wanted the first code. But then reversed. So I exported it as a video and literally reversed it.
Thanks anyway!