# Help with classes

**URL:** <https://discourse.processing.org/t/help-with-classes/13305>\
**Category:** Coding Questions\
**Created:** [August 11, 2019, 9:06am UTC](https://discourse.processing.org/t/help-with-classes/13305 "2019-08-11T09:06:09Z")\
**Posts on this page:** 6\
**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:** [August 11, 2019, 9:06am UTC](https://discourse.processing.org/t/help-with-classes/13305/1 "2019-08-11T09:06:09Z")

</div>

Hi, so I have a simple sketch of paint to colour in the background of a window. I want to make the colouring tool decrease and increase in size. Why does the code in the function changeSize not work?

Thanks in advance.

```auto
Circle c;

void setup() {
  size(600, 400);
  background(255);
  noStroke();
  
  c = new Circle();
}

void draw() {
  
  c.changeSize();
  
  if (mousePressed && (mouseButton == LEFT)) {
  c.display();
  }
  
  if (mousePressed && (mouseButton == RIGHT)) {
    background(255);
  }

}

class Circle {
  
  float d;
  
  Circle() {
    d = 100;
  }
  
  void display() {
    fill(0);
    ellipse(mouseX, mouseY, d, d);
  }
  
  void changeSize() {
    if (d > 100) {
      d = d - 1;
    } else if (d < 10) {
      d = d + 1;
    }
  }
  
}

```

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [August 11, 2019, 9:10am UTC](https://discourse.processing.org/t/help-with-classes/13305/2 "2019-08-11T09:10:38Z")

</div>

Hi,

You never enter either one of your conditions.

You start with d = 100.

So d \> 100 is false and d \< 10 is also false.

---

<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:** [August 11, 2019, 9:31am UTC](https://discourse.processing.org/t/help-with-classes/13305/4 "2019-08-11T09:31:47Z")

</div>

Hi, thanks for the reply! I understand it now. My code is now the below, but the circle will still not increase in size once d reaches 50?

```auto
Circle c;

void setup() {
  size(600, 400);
  background(255);
  noStroke();

  c = new Circle();
}

void draw() {

  if (mousePressed && (mouseButton == LEFT)) {
    c.display();
    c.decrease();
  }

  if (d < 50) {
    c.increase();
  }

  if (mousePressed && (mouseButton == RIGHT)) {
    background(255);
  }
}

float d;

class Circle {
  
  Circle() {
    d = 100;
  }
  
  void display() {
    fill(0);
    ellipse(mouseX, mouseY, d, d);
  }
  
  void decrease() {
    d = d - 1;
  }
  
  void increase() {
    d = d + 1;
  }
  
}

```

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 11, 2019, 9:56am UTC](https://discourse.processing.org/t/help-with-classes/13305/5 "2019-08-11T09:56:29Z")

</div>

> [@abigail](#):
>
> if (d \< 50) { c.increase(); }

Once d \>= 50 it can never increase again!

Note the draw method is executed 60 times a second so d starts as 100 but when you press the left mouse button this code is executed

> [@abigail](#):
>
> if (mousePressed && (mouseButton == LEFT)) { c.display(); c.decrease(); }

until d == 49 which happens very quickly at which point it is below 50 so is increased to 50 and then stays there for ever.

Note d is the diameter of the circle so should be in the Circle class like this. Note I have changed some of the code to display the diameter in the top left corner so you can experiment with different algorithms and see what works for you.

```auto
Circle c;

void setup() {
  size(600, 400);
  background(255);
  noStroke();

  c = new Circle();
}

void draw() {
  // show the circle diameter so we can see what is happening
  fill(255, 255, 0);
  noStroke();
  rect(0, 0, 80, 24);
  fill(0);
  text(c.d, 10, 20); 

  if (mousePressed && (mouseButton == LEFT)) {
    c.display();
    c.decrease();
  }

  if (c.d < 50) { // now d is an attribute of circle
    c.increase();
  }

  if (mousePressed && (mouseButton == RIGHT)) {
    background(255);
  }
}

class Circle {

  float d;

  Circle() {
    d = 100;
  }

  void display() {
    fill(0);
    ellipse(mouseX, mouseY, d, d);
  }

  void decrease() {
    d = d - 1;
  }

  void increase() {
    d = d + 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:** [August 11, 2019, 10:10am UTC](https://discourse.processing.org/t/help-with-classes/13305/6 "2019-08-11T10:10:18Z")

</div>

Thanks so so much! This is really helpful, although I still wonder if I’ll ever get the hang of this…😀

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [August 11, 2019, 10:29am UTC](https://discourse.processing.org/t/help-with-classes/13305/7 "2019-08-11T10:29:25Z")

</div>

> [@abigail](#):
>
> I still wonder if I’ll ever get the hang of this

I expect virtually every programmer thought that at one time 😄
