We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all,
I am trying to draw a random position and have my ellipse move/tween to a new random position on the canvas.
My code doesn't seem to be working, I think I have things in the wrong order but every attempt I make fails to achieve my desired output.
float x, y;
float x2, y2;
float damping = .03;
void setup() {
size(500,500);
smooth();
x = random(0,width);
y = random(0,height);
}
void draw() {
background(255);
x2 = random(0,width);
y2 = random(0,height);
x = x + (x2 - x) * damping;
y = y + (y2 - y) * damping;
ellipse(x,y,15,15);
x = random(0,width);
y = random(0,height);
}
Thanks.
Answers
The problem is that you are randomizing everything on each frame, 60 times per second! You need to draw the new position, and to keep origin and destination stable, until the goal is reached. So, you need another couple of coordinates to track the current position.
When the goal is reached, set it to the origin and draw random numbers to get a new goal.
Thanks, I tried slowing everything down, which seems to also work.
An example for (linear interpolation)/(linear movement):