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.
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.
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.
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 . (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