# Why does only p2 show up?

**URL:** <https://discourse.processing.org/t/why-does-only-p2-show-up/10217>\
**Category:** Coding Questions\
**Created:** [April 12, 2019, 5:29pm UTC](https://discourse.processing.org/t/why-does-only-p2-show-up/10217 "2019-04-12T17:29:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![abigail](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@abigail](https://discourse.processing.org/u/abigail)\
**Post date:** [April 12, 2019, 5:29pm UTC](https://discourse.processing.org/t/why-does-only-p2-show-up/10217/1 "2019-04-12T17:29:53Z")

</div>

Hi I’m very new to programming so excuse if this is an easy question, but why is only one of my particles showing up (p2)?

Thanks in advance 🙂

```auto
Particle p1;
Particle p2;

void setup() {
  size(600,400);
  p1 = new Particle(300,200,80);
  p2 = new Particle(70,70,100);
}

void draw() {
  background(0);
  p1.display();
  p2.display();
}

float x, y;
float r;

class Particle {
  
  Particle(float tempX, float tempY, float tempR) {
    x = tempX;
    y = tempY;
    r = tempR;
  }
  
  void display() {
    fill(255,0,0);
    ellipse(x,y,r*2,r*2);  
  }
  
}

```

---

<div class="post-metadata">

**Author:** ![zenemig](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/zenemig/32/4418_2.png) [@zenemig](https://discourse.processing.org/u/zenemig)\
**Post date:** [April 12, 2019, 5:42pm UTC](https://discourse.processing.org/t/why-does-only-p2-show-up/10217/2 "2019-04-12T17:42:36Z")

</div>

Hi, your variables x, y and r are globals.  
You need to put them inside the class, that way each Particle will be able to store its own values instead of looking for global values.

```auto
class Particle {
  
  float x, y, r;
  
  Particle(float tempX, float tempY, float tempR) {
    x = tempX;
    y = tempY;
    r = tempR;
  }
  
  void display() {
    fill(255,0,0);
    ellipse(x,y,r*2,r*2);  
  }
  
}

```

Take a look at this:  
[https://processing.org/tutorials/objects/](https://processing.org/tutorials/objects/)

---

<div class="post-metadata">

**Author:** ![abigail](https://avatars.discourse-cdn.com/v4/letter/a/a587f6/32.png) [@abigail](https://discourse.processing.org/u/abigail)\
**Post date:** [April 12, 2019, 6:02pm UTC](https://discourse.processing.org/t/why-does-only-p2-show-up/10217/3 "2019-04-12T18:02:36Z")

</div>

Hi there, thanks very much for the quick reply, helped a lot. 😁
