Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 KB | None | 0 0
  1.     public static boolean moveMouse(WidgetChild w) {
  2.        
  3.         int x = w.getAbsoluteX() + Random.nextInt(0, w.getWidth()), y = w.getAbsoluteY() + Random.nextInt(0, w.getHeight());
  4.        
  5.         int startX = Mouse.getX(),
  6.             startY = Mouse.getY(),
  7.             startDX = Mouse.getX(),
  8.             startDY = Mouse.getY(); // where mouse started
  9.         double distX = Math.abs( (double) startX - x ),
  10.                 distY = Math.abs( (double) startY - y ),
  11.                 dist = Math.sqrt( distX * distX + distY * distY ); // Distance from start to finish
  12.        
  13.         double width = 2.0 *  dist* ( (0.5 * (double) w.getWidth()) / Math.max(distX, distY));
  14.        
  15.         double time = Random.nextDouble(125, 150) + Random.nextDouble(90, 100) * (Math.log( 2.0 * dist / width ) / Math.log(2)); // fitts law brah
  16.        
  17.         double bPoint = 0;
  18.         if(dist > 100) bPoint = dist / 20; // Last 20% of the distance
  19.        
  20.         double friction = Random.nextDouble(-1.00, 1.00); //Random friction, to be safe
  21.        
  22.         for(int i = 0; i < (int) dist; i++) {
  23.             if(startDX < x)
  24.                 startDX++;
  25.             else if (startDX > x) startDX--;
  26.            
  27.             if(startDY < y)
  28.                 startDY++;
  29.             else if (startDY > y) startDY--;
  30.            
  31.             //TODO: save points, randomize using friction, find different friction for diff surfaces
  32.         }
  33.        
  34.         if(Mouse.getX() == x && Mouse.getY() == y) return true;
  35.         return false;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement