# STOP the explosion

**URL:** <https://discourse.processing.org/t/stop-the-explosion/5071>\
**Category:** Coding Questions\
**Created:** [October 31, 2018, 9:40pm UTC](https://discourse.processing.org/t/stop-the-explosion/5071 "2018-10-31T21:40:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)\
**Post date:** [November 1, 2018, 12:56am UTC](https://discourse.processing.org/t/stop-the-explosion/5071/2 "2018-11-01T00:56:16Z")

</div>

See below.

```auto
Particle [] pickles = new Particle [100];

void setup () {

  size (500, 500);
  smooth ();
  for (int i=0; i<pickles.length; i++) {
    pickles [i] = new Particle ();
  }
}

void draw () {
  background (0); //clear the background

  for (int i=0; i<pickles.length; i++) {
    pickles[i].update();
  }
}

class Particle {

  float x;
  float y;

  float velX ; // speed or velocity
  float velY;

  Particle () {
    //x and y position to be in middle of screen
    x = width/2;
    y = height/2;

    velX = random (-10, 10);
    velY = random (-10, 10);

} 

  void update () {

    x+=velX;
    y+=velY;
    // Stop them from going off the left side.
    if( x < 5 ){
      x = 5;
      velY = 0;
    }
    // Stop them from going off the right side.
    if( x > width - 5 ){
      x = width - 5;
      velY = 0;
    }
    // I will leave these two up to you!
    // TODO: Stop them from going out the top.
    // TODO: Stop them from going out the bottom.
    
    
        
    fill (255);
    ellipse (x, y, 10, 10);
  }
}

```

---

_[View the full topic](https://discourse.processing.org/t/stop-the-explosion/5071)._
