im not that good in english, sorry.
so i have ellipse that moves from the center to the edges. I need it to move back to the center when I click the mouse
int rad = 40; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed = 4.8; // Speed of the shape
float yspeed = 4; // Speed of the shape
int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom
void setup()
{
size(500, 500);
frameRate(60);
stroke(1);
ellipseMode(RADIUS);
// Set the starting position of the shape
xpos = width/2;
ypos = height/2;
}
void draw()
{
background(0);
// Update the position of the shape
xpos = xpos + ( xspeed * xdirection );
ypos = ypos + ( yspeed * ydirection );
if (xpos > width-rad || xpos < rad) {
xdirection *= -1;
}
if (ypos > height-rad || ypos < rad) {
ydirection *= -1;
}
//COLOR
float red = map(xpos,0, width, 0, 500);
float blue = map(ypos, 0, width, 0, 255);
float green= map(xpos,0,width, 0, 255);
fill(red, green, blue);
// Draw the shape
if (mousePressed == true) {
xpos = xpos - ( xspeed * xdirection ); //this is my problem
ypos = ypos - ( yspeed * ydirection ); //its just stops
ellipse(xpos, ypos, rad, rad);
} else {
ellipse(xpos, ypos, rad, rad);
}
}
it’s my first code like that so i think i have some other problem maybe, if u see something wrong pls tell me