Stuck working with classes not updating

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

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

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;
    }

}

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:


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.

1 Like

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.

1 Like

Here you can see some correction to the Poop class

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 :scream::grin:. (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

2 Likes