map()

i have this simple sketch,i know that i have to make it somehow with map(),but i dont completely understand the maths behind it,the final sketch i want to be like when the mouse moves at x,the curves somehow open,and being more vertical as the distance from mouse is increased.Any thoughts?

float dist;
float r = 50;

void setup() {
  size(640, 480);
}


void draw() {
  background(255);

  for (int i=0; i < width; i++ ) {


    float Xpos = i*10;
    float Ypos = height;



    if (Xpos<mouseX ) {




      Xpos = (i*10)-70;

    }
    if (Xpos>mouseX ) {
      Xpos = (i*10)+70;


    }

    stroke(255, 0, 0);
    noFill();
    curve(i*10, 0, i*10, 0, Xpos, height, Xpos, height);
  }
  fill(0, 255, 0);
  ellipse(mouseX, mouseY, r, r);
}
Tagged:

Answers

  • 1st take the distance d1 between your line (as it were on its own) and the mouse

    (for x and y?)

    2nd the smaller d1 the more you want to push it away from mouse (lens effect)

    newXpos = oldXPos + map(d1,-400,400,-40,40);// this is wrong

    use newXpos in line 36

Sign In or Register to comment.