We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey there, Althouhg I'm new into Processing, I really like the versatility of the software. However, since I'm a graphic designer, it is not easy to came up with the right formula to achieve a particular effect for my animation. That's the main reason to post here, I would like to learn and improve my knoweledge with the help of other members.
On to the point. I can make a circle follow the mouse, but in this occasion I need that the object have a delay so the mouse moves first and then the object. This is the code I already have:
==============================
PVector theBallPosition;
PVector theBallVelocity;
void setup(){
smooth();
frameRate(30);
size(400,400);
theBallPosition = new PVector(width/2,height/2);
theBallVelocity = new PVector(1.3,1);
}
void draw(){
noStroke();
background(100,0,200); // Background color
ellipseMode(CENTER);
ellipse(mouseX,mouseY,30,30); // Placing the circle
}
==============================
Any ideas how to solve this little problem?
Answers
The PVector tutorial already provides a fairly good example of what (I think) you want.
Perhaps something like this 1 too? :D
http://studio.processingtogether.com/sp/pad/export/ro.9GTDpA6dp4tH1/latest
Thanks a lot for you prompt response. I will try to use the information and then I will get back with my solution (if I find one).
Almost there:
But I don't want the ball to be pushed. I need that the ball follow the mouse with some delay. Any ideas?
Try using GoToLoop's code with PVector. He uses an array for a reason, it introduces the delay you want, memorizing each step of the mouse (or at least a number of them).
OK, here is a version of GoToLoop's code, without tricks, with PVector.
Sounds good, but I need to present the result with the most simple solution possible. Is there any way to change something in my code to make it work?
Do you understand the idea of the implementation, particularly what the for loop does? And why it is necessary?
Just updating my example to ellipse() oldest entry only: <):)
I have some vague idea of what the code does... However, I don;t think I could explain it properly. GoToLoop code is really nice and is exactly what I want but I'm not sure what is going on in there!
Arrays x & y memorizes latest NUM mouseX & mouseY values.
At each draw() iteration, those mouse coordinates enter those arrays from their tail. That is, their POS index.
Of course, we gotta get rid of oldest entry to make room for newest coordinates!
In order to achieve that, the
for
loop block rotates everything to left, towards the head.So oldest entry, which is the head index 0, is lost. And it's replaced by following index 1.
In the end, latest POS index, which is tail index, becomes vacant.
And thus we got room to store current mouseX & mouseY coordinates! :P
And finally, an ellipse() is drawn using oldest entry, which is the head index 0! (*)
As you can see, we got an emulated queue structure using array.
That is, values get in from tail and get out from head. This is called FIFO. :ar!
https://en.wikipedia.org/wiki/FIFO