# Unwanted Color Changes

**URL:** <https://discourse.processing.org/t/unwanted-color-changes/14855>\
**Category:** Coding Questions\
**Created:** [October 21, 2019, 10:05am UTC](https://discourse.processing.org/t/unwanted-color-changes/14855 "2019-10-21T10:05:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ozhan](https://avatars.discourse-cdn.com/v4/letter/o/f9ae1b/32.png) [@Ozhan](https://discourse.processing.org/u/Ozhan)\
**Post date:** [October 21, 2019, 10:05am UTC](https://discourse.processing.org/t/unwanted-color-changes/14855/1 "2019-10-21T10:05:09Z")

</div>

Hi All. I wrote the following codes to follow my mouse when I pressed the left button with red and when I pressed the right button with green colors but color of all the shapes changes when I changed the mouse buttons.

It must start new shapes with new color and must not change the rest/left ones when I change the mouse buttons but it changes the color of all.

I need your guide. Thanks.

Here is the code

```auto
ArrayList <PVector> points= new ArrayList <PVector>();
float x, y;
float easing = 0.2;
float diameter = 12;
int distance=100;
int a;
void setup() {
  size(1200, 1000);
  background(0);
  smooth();
  surface.setResizable(true);
  colorMode(RGB);
}
void draw() {
  float targetX = mouseX;
  float targetY=mouseY;
  y += (targetY - y) * easing;
  x += (targetX - x) * easing;
  if (mousePressed&&mouseButton==LEFT) {
    points.add(new PVector(x, y));

    for (int i=0; i<points.size(); i++) {
      float k= points.get(i).x;
      float l = points.get(i).y;
      stroke(255, 0, 0);
      fill(255, 0, 0);
      ellipse(k, l, 12, 12);
      println(targetX + " : " + x);
     
      if (points.size()>distance) {
        points.remove(0);
        clear();
      }
    }
  }  
  if (mousePressed&&mouseButton==RIGHT) {
    points.add(new PVector(x, y));

    for (int i=0; i<points.size(); i++) {
      float m= points.get(i).x;
      float n = points.get(i).y;
      stroke(0, 255, 0);
      fill(0, 255, 0);
      ellipse(m, n, 12, 12);
      println(targetX + " : " + x);
      if (points.size()>distance) {
        points.remove(0);
        clear();
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 22, 2019, 4:13am UTC](https://discourse.processing.org/t/unwanted-color-changes/14855/2 "2019-10-22T04:13:50Z")

</div>

can you please copy your above code back to a blank  
PDE sketch and tell me why it is not running?

code paste please use

```auto
</> Preformatted text button from editor menu

```

looks like  
```  
type or paste code here  
```

* * *

anyhow from program flow i understand:  
on mouse button press you want add a new vector to a array.

and then draw all from array circles

with the only difference that  
on mouse RIGHT GREEN  
on mouse LEFT RED

so actually you could take out all that code from the IF ( and put below )  
only change the color inside.

* * *

but actually you not want that at all,  
sorry, if you want each circle to have its own color you need a memory for that.  
and a PVector is not the best one ( could use .z )

so need color array ( same long as PVector )

or move position vector and color inside a class.
