Sine wave with slower peaks - in / out animation
in
Programming Questions
•
2 years ago
I'm trying to get a slow in, slow out animation. The below example code works, but I'd like to get something that is a little slower on the in and out, while maintaining a quick middle. Something like the Cubic in/out easing on the Ani library. Any suggestions?
- float movementpos = 0;
- float startx = 200;
- float starty = 200;
- float x = 200;
- float y = 200;
- float endx, endy;
- boolean startmovement;
- void setup() {
- size(400, 400);
- smooth();
- }
- void draw() {
- background(0);
- if (startmovement) {
- moveme();
- }
- ellipse(x, y, 20, 20);
- }
- void moveme() {
- float movepos = (cos(movementpos)-1)/-2;
- x = lerp(startx, endx, movepos);
- y = lerp(starty, endy, movepos);
- movementpos += (TWO_PI/100.0);
- if (degrees(movementpos) > 180) {
- x = endx;
- y = endy;
- startx = endx;
- starty = endy;
- startmovement = false;
- }
- }
- void mouseClicked() {
- startx = x;
starty = y; - endx = mouseX;
- endy = mouseY;
- movementpos = 0;
- startmovement = true;
- }
1