Advertisement
Guest User

AutoMassDraw

a guest
Jul 20th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.23 KB | None | 0 0
  1. package pkg_paintAsEngine;
  2.  
  3. import java.awt.AWTException;
  4. import java.awt.Robot;
  5. import java.awt.event.InputEvent;
  6. import java.awt.event.KeyEvent;
  7. import java.util.Random;
  8.  
  9. public class Drawing {
  10.  
  11. private static final int TINY = 1;
  12. private static final int SMALL = 1000;
  13. private static final int MEDIUM= 10000;
  14. private static final int LARGE = 100000;
  15. private static final int HUGE = 1000000;
  16. private static final int OMFG = 10000000;
  17.  
  18. private static Robot rob;
  19. private static int topLeftCornX, topLeftCornY, canvWidth, canvHeight, clearBtnX, clearBtnY, massTxtBoxX, massTxtBoxY;
  20.  
  21. public static void main(String[] args) throws AWTException {
  22.  
  23. rob = new Robot();
  24. rob.setAutoDelay(2);
  25.  
  26. init(0, 130, 1920, 700, 180, 975, 75, 875);
  27. waitForSeconds(3);
  28. clearScreen();
  29. chooseMass(HUGE);
  30. // for(int i = 0; i < 800; i+=100){
  31. // chooseMass((int)Math.pow(10, i/100));
  32. // drawMovingMass(50, i, 100, 0);
  33. // }
  34. }
  35.  
  36. private static int function(int x){
  37. return x * x;
  38.  
  39. }
  40.  
  41. private static void init (
  42. int topLeftCornerX, int topLeftCornerY,
  43. int canvasWidth, int canvasHeight,
  44. int clearButtonX, int clearButtonY,
  45. int massTextBoxX, int massTextBoxY) {
  46.  
  47. topLeftCornX = topLeftCornerX;
  48. topLeftCornY = topLeftCornerY;
  49. canvWidth = canvasWidth;
  50. canvHeight = canvasHeight;
  51. clearBtnX = clearButtonX;
  52. clearBtnY = clearButtonY;
  53. massTxtBoxX = massTextBoxX;
  54. massTxtBoxY = massTextBoxY;
  55.  
  56. }
  57.  
  58. private static void chooseMass(int mass){
  59. rob.mouseMove(massTxtBoxX, massTxtBoxY);
  60. click();
  61. waitForSeconds(0.1);
  62. click();
  63. waitForSeconds(0.5);
  64. typeNumber(mass);
  65. }
  66.  
  67. private static void drawMass(int x, int y) {
  68. click();
  69. moveOnCanvas(x, y);
  70. click();
  71. }
  72.  
  73. private static void drawMovingMass (int x, int y, int moveVectorX, int moveVectorY) {
  74. moveOnCanvas(x, y);
  75. rob.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  76. moveOnCanvas(x + moveVectorX, y + moveVectorY);
  77. rob.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  78. }
  79.  
  80.  
  81. //useless?
  82. // private static void drawRect (int x, int y, int width, int height) {}
  83.  
  84. private static void drawCircle(int x, int y, int r, boolean random){
  85. if(random){
  86. for(int i = 0; i <= r/4; i++){
  87. int l = new Random().nextInt(r+1);
  88. int calcedX = (int) Math.sqrt((r * r) - (l * l));
  89. drawMass(x+calcedX, y + l);
  90. drawMass(x-calcedX, y + l);
  91. drawMass(x-calcedX, y - l);
  92. drawMass(x+calcedX, y - l);
  93. }
  94. }
  95. else{
  96. for(int i = 0; i <= r; i+=2){
  97. int calcedX = (int) Math.sqrt((r * r) - (i * i));
  98. drawMass(x+calcedX, y + i);
  99. }
  100. for(int i = 0; i <= r; i+=2){
  101. int calcedX = (int) Math.sqrt((r * r) - (i * i));
  102. drawMass(x-calcedX, y + i);
  103. }
  104. for(int i = 0; i <= r; i+=2){
  105. int calcedX = (int) Math.sqrt((r * r) - (i * i));
  106. drawMass(x-calcedX, y - i);
  107. }
  108. for(int i = 0; i <= r; i+=2){
  109. int calcedX = (int) Math.sqrt((r * r) - (i * i));
  110. drawMass(x+calcedX, y - i);
  111. }
  112. }
  113. }
  114.  
  115. private static void drawFunction(int xAxisScale, int yAxisScale){
  116. int i = 0;
  117. while(i * xAxisScale < canvWidth && function(i) * yAxisScale < canvHeight && i <= 100){
  118. drawMass(i * xAxisScale, function(i) * yAxisScale);
  119. i++;
  120. }
  121. }
  122.  
  123. private static void clearScreen () {
  124. rob.mouseMove(clearBtnX, clearBtnY);
  125. click();
  126. }
  127.  
  128. private static void click () {
  129. rob.mousePress(InputEvent.BUTTON1_DOWN_MASK);
  130. rob.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
  131. }
  132.  
  133. private static void moveOnCanvas(int x, int y){
  134. if(!(x > canvWidth || y > canvHeight)) rob.mouseMove(topLeftCornX + x, topLeftCornY + y);
  135. }
  136.  
  137. private static void waitForSeconds(double seconds){
  138. long startTime = System.currentTimeMillis();
  139. while(((double)(System.currentTimeMillis() - startTime))/1000 <= seconds) {
  140. //wait patiently
  141. }
  142. }
  143.  
  144. private static int averageVal(int[] values){
  145. int addedVals = 0;
  146. for(int i = 0; i < values.length; i++){
  147. addedVals += values[i];
  148. }
  149. return addedVals / values.length;
  150. }
  151.  
  152. private static void typeNumber(int n){
  153. char[] ca = String.valueOf(n).toCharArray();
  154. for(char c : ca){
  155. typeNumberKey(c);
  156. }
  157. }
  158.  
  159. private static void typeNumberKey(char n){
  160. switch(n){
  161. case '0':
  162. rob.keyPress(KeyEvent.VK_0);
  163. rob.keyRelease(KeyEvent.VK_0);
  164. break;
  165. case '1':
  166. rob.keyPress(KeyEvent.VK_1);
  167. rob.keyRelease(KeyEvent.VK_1);
  168. break;
  169. case '2':
  170. rob.keyPress(KeyEvent.VK_2);
  171. rob.keyRelease(KeyEvent.VK_2);
  172. break;
  173. case '3':
  174. rob.keyPress(KeyEvent.VK_3);
  175. rob.keyRelease(KeyEvent.VK_3);
  176. break;
  177. case '4':
  178. rob.keyPress(KeyEvent.VK_4);
  179. rob.keyRelease(KeyEvent.VK_4);
  180. break;
  181. case '5':
  182. rob.keyPress(KeyEvent.VK_5);
  183. rob.keyRelease(KeyEvent.VK_5);
  184. break;
  185. case '6':
  186. rob.keyPress(KeyEvent.VK_6);
  187. rob.keyRelease(KeyEvent.VK_6);
  188. break;
  189. case '7':
  190. rob.keyPress(KeyEvent.VK_7);
  191. rob.keyRelease(KeyEvent.VK_7);
  192. break;
  193. case '8':
  194. rob.keyPress(KeyEvent.VK_8);
  195. rob.keyRelease(KeyEvent.VK_8);
  196. break;
  197. case '9':
  198. rob.keyPress(KeyEvent.VK_9);
  199. rob.keyRelease(KeyEvent.VK_9);
  200. break;
  201. default:
  202. System.out.println("Use typeNumber(int n) for numbers larger than 9!");
  203. break;
  204. }
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement