easing inside a function
in
Programming Questions
•
2 years ago
Hi everyone,
I am having a problem when I try to put easing inside of a function that would draw lines. Essentially, I wrote a function where you give the coordinates of 2 line segments and when the mouse is all the way left it is the first line, and as you move the mouse right, it moves to the position of the second. I got that part of the code working, but when I added easing to the mix, everything went wacky. Here is my code:
- float easing = 0.05;
- void setup(){
- size(640,480);
- smooth();
- }
- void movingLine(float X11, float Y11, float X12, float Y12, float X21, float Y21, float X22, float Y22){
- float x1 = 0;
- float x2 = 0;
- float y1 = 0;
- float y2 = 0;
- float lineX1 = map(mouseX,0,width, X11,X21);
- float lineX2 = map(mouseX,0,width, X12,X22);
- float lineY1 = map(mouseX,0,width, Y11,Y21);
- float lineY2 = map(mouseX,0,width, Y12,Y22);
- float dx1 = lineX1-x1;
- if(abs(dx1) > 1){
- x1 += dx1 * easing;
- }
- float dy1 = lineY1-y1;
- if(abs(dy1) > 1){
- y1 += dy1 * easing;
- }
- float dx2 = lineX2-x2;
- if(abs(dx2) > 1){
- x2 += dx2 * easing;
- }
- float dy2 = lineY2-y2;
- if(abs(dy2) > 1){
- y2 += dy2 * easing;
- }
- line(x1,y1,x2,y2);
- }
Help?
1