Hello
given the code below, do you see a simple way to modify it as keep the blue ball to move along the line, when the starting point is given by (mouseX, mouseY)?
thanks cheers m.
float xi=50;
float yi=50;
float x =xi;
float y =yi;
float tx=1200;
float ty=700;
float slope;
int s=1;
void setup() {
size(1400, 760);
}
void draw() {
// xi=mouseX; // how do I introduce mouseX, mouseY and keep moving along a line?
// yi=mouseY;
background(255);
fill(255,0,0);
circle(xi,yi,25); //start
circle(tx,ty,25); //target
line(xi,yi,tx,ty);
slope = ((ty-yi)/(tx-xi));
fill(0,0,255);
ellipse(x,y,25,25); // moving along the line
x+=s;
y+=slope;
if(x>tx){x=xi;}
if(y>ty){y=yi;}
}