Why do my ellipse become bigger when it "further away" processing

Hello, I have a problem the ellipse size becomes smaller when I use mousePressed but as it is further away it becomes bigger and bigger.

float gravity = .4;
int particle_each_time = 4;
ArrayList<Particle> particle= new ArrayList<Particle>(); // ArrayList to manage to list of all particles


void setup() {
  size(640,480);
}

void draw() {
  background(0);
  for (int i = 0; i < particle_each_time; i++) {
    particle.add(new Particle(mouseX,mouseY));
  }
  for (int i = 0; i < particle.size(); i++) {
    Particle p = particle.get(i);
    p.update(gravity);
    p.draw();
  }
  
}
 void mousePressed() {
}



class Particle{
  float x; //X Position
  float y; //Y Position
  float velX; //velocity on X axis
  float velY; //velocity on Y axis
  float size; // Size of the particle
  float lifespan; // duration of the particle
  float col;//create fire type colours
  
  Particle(float x,float y){
    this.velY = random(-10,10);
    this.velX = random(-10,10);
    this.x = x;
    this.y = y;
    this.size = 15;
    lifespan = 220.0;
    col = random(#DE8816);
  }
  
  void update(float gravity){
    this.x += velX; // direction of X axis
    velY += gravity; // gravity affectiing the velocity on Y axis causing to fall
    this.y += velY; //direction of Y axis
    lifespan -= 1.0;
    if (mousePressed ) {
      size--;
    }
   
  }
  
  boolean isDead() {
    if (lifespan < 0.0) {
      return true;
    } else {
      return false;
    }
  } 
  
  void draw() {
    stroke(0,lifespan);
    fill(#DE8816,lifespan);
    ellipse(x,y,size,size);
  }
  
}

size of the ellipse can get smaller than 0

Then it’s getting bigger and bigger (probably the right side being left now…)

Check if (size<0) and then set size=1;

1 Like

I see thank you very much, dint know that

1 Like