Processing, unable to set alpha value for objects in ArrayList
<p>This is a follow up to this <a href="https://stackoverflow.com/questions/39218251/processing-ellipse-not-following-alpha-values/39227721#39227721">question</a>.</p>

<p>I am looking to get a bunch of particle objects to stay at a certain 'alpha' value. This alpha value will increase/decrease based on its proximity with neighboring particles. </p>

<p>Currently the code I have results in all particles staying at max alpha. I believe this is due to the iterating through the ArrayList results in the alpha being redrawn multiple times. The program runs sluggishly due to this too.</p>

<pre><code>  class Particle{

  PVector velocity, location; //PVector variables for each particle.

  Particle(){ //Constructor - random location and speed for each particle.
    velocity = new PVector(random(-0.5,0.5), random(-0.5,0.5));
    location = new PVector(random(0,width),random(0,width));
  }

  void update() { location.add(velocity); } //Motion method.

  void edge() {  //Wraparound case for particles.
    if (location.x &gt; width) {location.x = 0;} 
    else if (location.x &lt; 0) {location.x = width;}

    if (location.y &gt; height) {location.y = 0;}
    else if (location.y &lt; 0) {location.y = height;}
  }

  void display(ArrayList&lt;Particle&gt; p){ //Display method to show lines and ellipses between particles.

    for(Particle other: p){ //For every particle in the ArrayList.
     float d = PVector.dist(location,other.location); //Get distance between any two particle.
     float a = 255 - map(d,0,112,0,255); //Map variable 'a' as alpha based on distance. E.g. if distance is high, d = 100, alpha is low, a = 255 - 225 = 30.

if(other==this){continue;}

     println("Lowest distance of any two particle =" + d); //Debug output.

     if(d&lt;112){ //If the distance of any two particle falls bellow 112.
      noStroke(); //No outline.
      fill(0,a); //Particle are coloured black, 'a' to vary alpha.
      ellipse(location.x, location.y, 8, 8); //Draw ellipse based on location of particle.

    }else{
      noStroke(); //No outline.
      fill(0,30); //For particles far away, set them to a fix alpha of '30'
      ellipse(location.x, location.y, 8, 8); //Draw ellipse based on location of particle.
    }
  }
}
}

ArrayList&lt;Particle&gt; particles = new ArrayList&lt;Particle&gt;(); //Create a new arraylist of type Particle.

void setup(){
  size(640,640,P2D); //Setup frame of sketch.

    for (int i=0; i&lt;40; i++) { 
  particles.add(new Particle()); //Add five Particle elements into arraylist.
    }
}

void draw(){
 background(255); //Set white background.
 for(Particle p: particles){ //For every 'p' of type Particle in arraylist particles.
   p.update(); //Update location based on velocity.
   p.display(particles); //Display each particle in relation to other particles.
   p.edge(); //Wraparound if particle reaches edge of screen.
 }
}
</code></pre>