[ + | - ]

Example 5-13: Find The Cursor

PROCESSING

Example 5-13: Find The Cursor

float xVal;
int offsetVal = 10;

void setup() {
   size(240,120);
   xVal = width/2; // xVal is in the center
}

void draw() {
   background(204);
   if (mouseX > xVal) {
      xVal += 0.5;
      offsetVal = -10;
   }
   if (mouseX < xVal) {
      xVal -= 0.5;
      offsetVal = 10;
   }
   // Draw arrow left or right depending on "offsetVal" 
   line(xVal, 0, xVal, height);
   line(mouseX, mouseY, mouseX + offsetVal, mouseY - 10);
   line(mouseX, mouseY, mouseX + offsetVal, mouseY + 10);
   line(mouseX, mouseY, mouseX + (offsetVal*3), mouseY);
}