# Stuck working with classes not updating

**URL:** <https://discourse.processing.org/t/stuck-working-with-classes-not-updating/1359>\
**Category:** Coding Questions\
**Created:** [June 29, 2018, 8:46am UTC](https://discourse.processing.org/t/stuck-working-with-classes-not-updating/1359 "2018-06-29T08:46:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wontner](https://avatars.discourse-cdn.com/v4/letter/w/ecae2f/32.png) [@wontner](https://discourse.processing.org/u/wontner)\
**Post date:** [June 29, 2018, 8:46am UTC](https://discourse.processing.org/t/stuck-working-with-classes-not-updating/1359/1 "2018-06-29T08:46:40Z")

</div>

Hello, I’m stuck, I’m trying to create a class with ellipse that will go from one place to another, with the help of sinus and cosinus curves. but when I wrote the class and the method and then call it in draw. it doesn’t update. and I cant find the bug. please help.

this is the main PDE

```auto
Poop P1 = new Poop(0.08,0.08,100,100,500,500);

void setup(){
size(1000,1000);

background(100);

}

void draw(){

fill(255);

P1.init();

}

```

Here is the Class PDE

```auto
class Poop {

float xangle;
float yangle;
float xdistance;
float ydistance;
float xstart;
float ystart;

    Poop(float xa, float ya, float xd, float yd, float xs, float ys){

    xa = xangle ;
    ya = yangle ;
    xd = xdistance ;
    yd = ydistance ;
    xs = xstart ;
    ys = ystart ;
    }

    void init(){
    float x = xstart + sin(xangle) * xdistance;
    float y = ystart + cos(yangle) * ydistance;
    ellipse(x,y,100,100);
    x = x + 1;
    y = y + 1;
    }

}

```

---

<div class="post-metadata">

**Author:** ![mat650](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mat650/32/564_2.png) [@mat650](https://discourse.processing.org/u/mat650)\
**Post date:** [June 29, 2018, 12:19pm UTC](https://discourse.processing.org/t/stuck-working-with-classes-not-updating/1359/2 "2018-06-29T12:19:07Z")

</div>

I don’t know exactly what’s your aim, which result you are expecting, I made some correction to make it work. This is the main sketch:

```auto

Poop P1; 

void setup(){
size(1000,1000);
frameRate(2);
P1 = new Poop(0.08,0.08,100,100,500,500);
}

void draw(){
background(100);

fill(255);
P1.init();
}

```

The background must be called at the beginning of the draw() method otherwise the elements will overlap on one single background.  
I also called frameRate and gave it as argument a low value that slow down the execution of the program. This way you can better see if the sketch is executing as expected.

---

<div class="post-metadata">

**Author:** ![neilcsmith](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/neilcsmith/32/144_2.png) [@neilcsmith](https://discourse.processing.org/u/neilcsmith)\
**Post date:** [June 29, 2018, 12:26pm UTC](https://discourse.processing.org/t/stuck-working-with-classes-not-updating/1359/3 "2018-06-29T12:26:05Z")

</div>

Why are you adding 1 to x & y and then immediately discarding those values? Nothing changes between one call to init() and the next because you’re not storing any updated values outside the method.

---

<div class="post-metadata">

**Author:** ![mat650](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mat650/32/564_2.png) [@mat650](https://discourse.processing.org/u/mat650)\
**Post date:** [June 29, 2018, 12:26pm UTC](https://discourse.processing.org/t/stuck-working-with-classes-not-updating/1359/4 "2018-06-29T12:26:43Z")

</div>

Here you can see some correction to the Poop class

```auto
class Poop{

float xangle;
float yangle;
float xdistance;
float ydistance;
float xstart;
float ystart;

    Poop(float xa, float ya, float xd, float yd, float xs, float ys){

    this.xangle = xa;
    this.yangle = ya ;
    this.xdistance = xd ;
    this.ydistance = yd ;
    this.xstart = xs ;
    this.ystart = ys ;
    }
    
float x = xstart;
float y = ystart;

    void init(){
    x = x + sin(xangle) * xdistance;
    y = y + cos(yangle) * ydistance;
    ellipse(x,y,100,100);
    x++;
    y++;
    }
}

```

First of all the construction was the other way around. It was assigning the value of the “not initialized” class variables to the constructor arguments 😱😁. (which is not possible) . You want to do the opposite and assign the value of the arguments to the class variable.  
Second the value of xstart and ystart is to assign to x and y only one time after. therefor, the assigning statement must be placed out of the method init(), otherwise the ellipse will start each frame at the same position
