We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I need some direction how to implement something like that (link) into processing.
This is my code right now:
ArrayList xPositions = new ArrayList();
ArrayList yPositions = new ArrayList();
void setup() {
size(640, 360);
xPositions.add((int) width / 2);
yPositions.add((int) height / 2);
}
void draw() {
background(0, 0, 255);
ball();
}
void mousePressed() {
xPositions.add( mouseX );
yPositions.add( mouseY );
}
void ball() {
int ballSize = 8;
connectingBallLine();
// Balls parameters
strokeWeight(1);
stroke(0);
fill(255);
for ( int i = 0; i < xPositions.size(); i++)
ellipse( (int) xPositions.get(xPositions.size()-1), (int) yPositions.get(xPositions.size()-1), ballSize, ballSize);
}
void connectingBallLine() {
for ( int i = 0; i < xPositions.size()-1; i++) {
arrow((int) xPositions.get(xPositions.size()-2), (int) yPositions.get(yPositions.size()-2), (int) xPositions.get(xPositions.size()-1), (int) yPositions.get(yPositions.size()-1), 8);
}
}
// Function for creating arrow
void arrow(float x1, float y1, float x2, float y2, float s) {
strokeWeight(1);
stroke(0);
line(x1, y1, x2, y2);
pushMatrix();
translate(x2, y2);
float a = atan2(x1-x2, y2-y1); // 70, 360
rotate(a);
line(0, 0, -s, -s);
line(0, 0, s, -s);
popMatrix();
}
So instead of an arrow I would like to have animation just like in the video above. Can you guys give me some clues or tips how to do that?
Answers
Look at lerp
When you increase your amt (in lerp) slowly in draw, you see a smooth transition from a to b
You mean lerp function yeah? I will look at this, thanks again @Chrisir :-bd
I like this better. Try it-
Also see the code in reference for lerp()
Look at PVector to make an ArrayList of type PVector that holds both x and y
@kevo1414 -- See also this previous discussion of a sketch that left traces of previous ball positions behind:
jeremydouglass idea is indeed very good
@kevo1414 here is your sketch with PVector
So I watched some videos on YT about PVectors. If I understand it correctly, PVector is a class which can store two values. Instead of two variables which stores x and y values, we can store x and y value in one variable. Yes?
In code above that you posted @Chrisir, we have an arrayList in which we can store only PVectors (line 1). And each time we pressed the mouse button, in arrayList positons goes PVector with two values. xMouse and yMouse.
If this is true I don't know why ConnectingBallLine() does not work correctly with PVectors.
How can I use lerp() with PVectors? It is possible do to something like that:
?
Yes
x=lerp(pv1.x,pv2.x, 0.5);
y=....
This is with PVectors. If I change code in connectingBallLine() like below, I get someting similiar with no PVectors but on my sketch stays previus ellipses.
I hope you understand what I want to tell you, my english is not perfect so excuse me for this :(
lerp is for a smooth transition between pv1 and pv2
Like for a ball that flies between them
Ok nevermind about above post. Code below is the same code as the first code in this topic only that we included PVectors
What do you need now?
Transition between balls with lerp() function.
But I don't know where do I need to put this lerp() function neither how to use it.
If I use lerp() function in connectingBallLine() function like below (line 41, 42), I got arrow transition and not ball transition that I want. Understood?
Actually it is 3
float
fields: x, y & z. Look up its reference: L-)https://Processing.org/reference/PVector.html
Yep, I notice that but I did not want to complicate things. :P Thanks
;-)
I'll take a look
this doesn't really make sense:
Don't you want to loop over all entries? So shouldn't you say
positions.get(i)
instead?homework?
Sorry for late respond, I was in hospital for two days.
Woow this is amazing stuff. This is what I wanted. Thanks for your big help! I really appreciate your help, I don't know what I would do without you. ^:)^
This is very good but still I try to achive this.
But /Lord_of_the_Galaxy
already showed you how.....?
You can also combine his and my idea?
What this code from @Lord_of_the_Galaxy do?
Video
The ellipses get weaker because of weak background that gets drawn over the images