We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi All,
I do have now this code. The element will bounce to the borders in horizontal direction. From the left to the right the speed starts fast and the speed will slow at the end. When the element hits the right side, the element will bounce back.
From the right to the left the speed now start slow and will speed-up at the end. I do want to do this the other way around for the movement from right to the left where it starts fast and will slow at the end.
float x;
float y;
float easing = 0.05;
float targetX;
float dx;
float w = 100;
float h = 50;
void setup() {
size(640, 360);
noStroke();
}
void draw() {
background(51);
targetX = width+25-w;
dx = targetX - x;
x += dx * easing;
if (x < 25) {
targetX = width+25;
dx = targetX - x;
easing = 0.04;
}
if (x > width - w) {
targetX = 0;
dx = targetX;
x += dx * -easing;
easing = -0.04;
}
float targetY = mouseY;
float dy = targetY - y;
y += dy * easing;
rect(x, height/2, w, h);
}
Answers
why does it say Lerp in the title? you don't use linear interpolation anywhere.
You are right, i will change it. can you help me
why is line 19 unconditional but line 28 is within the condition?
Its still just a test
you can do easing with bezierPoint
Check this: https://forum.processing.org/two/discussion/comment/99933/#Comment_99933
Shiffman uses lerp in his video as you can see in one of the posts.
Kf
your code was more complicated than it needed to be. the main thing is that speed towards the target is proportional to distance from it
what is odd is that your targets are unbalanced. so the speed going in one direction gets down to -26, slows down quite a lot, but in the other direction it doesn't go down below 130. that's to do with when you turn and where you set the new target. (lines 28 to 33)
Thank you all!
you are right. and what this is doing is moving hueSlider to a place 1% nearer to slider value, which, of course, slows down as the distance decreases. it's neat, but not particularly clear (but nothing a comment wouldn't cure)