madhawaseeeee

draw

Feb 9th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.75 KB | None | 0 0
  1. package sinhalatype;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Robot;
  5. import java.awt.event.InputEvent;
  6.  
  7. public class tanc {
  8.  
  9.     public static void main(String[] args) throws InterruptedException, AWTException {
  10.         Thread.sleep(3000);
  11.         int tx = 400, ty = 450;
  12.         int dx = 600, dy = 450;
  13.  
  14.         double m = (ty - dy) / (double) (tx - dx);
  15.         double c = dy - m * dx;
  16.         // System.out.println(c);
  17.  
  18. ///////////////////////////////////////////////////
  19.         int div = 10;
  20.         int p = 300;
  21.         int d = (int) Math.sqrt((dx - tx) * (dx - tx) + (dy - ty) * (dy - ty));
  22.         System.out.println("d " + d);
  23.         int x = (dx * (p + d) - p * tx) / d;
  24.         int y = (dy * (p + d) - p * ty) / d;
  25.         //System.out.println(x+" "+y);
  26.         System.out.println("dx " + x + " " + dx);
  27.         Robot robot = new Robot();
  28.         robot.mouseMove(dx, dy);
  29.         robot.mousePress(InputEvent.BUTTON1_MASK);
  30.         if ((x - dx) != 0) {
  31.             int n = dx;
  32.             int amount = (x - dx) / Math.abs(x - dx);
  33.             while (n != x) {
  34.                 n += amount;
  35.                 int yn = (int) (m * n + c);
  36.                 System.out.println(n + " " + yn);
  37.                 robot.mouseMove(n, yn);
  38.                 Thread.sleep(10);
  39.             }
  40.         } else {
  41.             int ydy = y - dy;
  42.             int absy = Math.abs(y - dy);
  43.             int amount = (y - dy) / Math.abs(y - dy);
  44.             int v = dy;
  45.             while (v != y) {
  46.                 v += amount;
  47.                 System.out.println(x + " " + v);
  48.                 robot.mouseMove(x, v);
  49.                 Thread.sleep(10);
  50.  
  51.             }
  52.            
  53.         }
  54.         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  55.  
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment