Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pkg_paintAsEngine;
- import java.awt.AWTException;
- import java.awt.Robot;
- import java.awt.event.InputEvent;
- import java.awt.event.KeyEvent;
- import java.util.Random;
- public class Drawing {
- private static final int TINY = 1;
- private static final int SMALL = 1000;
- private static final int MEDIUM= 10000;
- private static final int LARGE = 100000;
- private static final int HUGE = 1000000;
- private static final int OMFG = 10000000;
- private static Robot rob;
- private static int topLeftCornX, topLeftCornY, canvWidth, canvHeight, clearBtnX, clearBtnY, massTxtBoxX, massTxtBoxY;
- public static void main(String[] args) throws AWTException {
- rob = new Robot();
- rob.setAutoDelay(2);
- init(0, 130, 1920, 700, 180, 975, 75, 875);
- waitForSeconds(3);
- clearScreen();
- chooseMass(HUGE);
- // for(int i = 0; i < 800; i+=100){
- // chooseMass((int)Math.pow(10, i/100));
- // drawMovingMass(50, i, 100, 0);
- // }
- }
- private static int function(int x){
- return x * x;
- }
- private static void init (
- int topLeftCornerX, int topLeftCornerY,
- int canvasWidth, int canvasHeight,
- int clearButtonX, int clearButtonY,
- int massTextBoxX, int massTextBoxY) {
- topLeftCornX = topLeftCornerX;
- topLeftCornY = topLeftCornerY;
- canvWidth = canvasWidth;
- canvHeight = canvasHeight;
- clearBtnX = clearButtonX;
- clearBtnY = clearButtonY;
- massTxtBoxX = massTextBoxX;
- massTxtBoxY = massTextBoxY;
- }
- private static void chooseMass(int mass){
- rob.mouseMove(massTxtBoxX, massTxtBoxY);
- click();
- waitForSeconds(0.1);
- click();
- waitForSeconds(0.5);
- typeNumber(mass);
- }
- private static void drawMass(int x, int y) {
- click();
- moveOnCanvas(x, y);
- click();
- }
- private static void drawMovingMass (int x, int y, int moveVectorX, int moveVectorY) {
- moveOnCanvas(x, y);
- rob.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- moveOnCanvas(x + moveVectorX, y + moveVectorY);
- rob.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- }
- //useless?
- // private static void drawRect (int x, int y, int width, int height) {}
- private static void drawCircle(int x, int y, int r, boolean random){
- if(random){
- for(int i = 0; i <= r/4; i++){
- int l = new Random().nextInt(r+1);
- int calcedX = (int) Math.sqrt((r * r) - (l * l));
- drawMass(x+calcedX, y + l);
- drawMass(x-calcedX, y + l);
- drawMass(x-calcedX, y - l);
- drawMass(x+calcedX, y - l);
- }
- }
- else{
- for(int i = 0; i <= r; i+=2){
- int calcedX = (int) Math.sqrt((r * r) - (i * i));
- drawMass(x+calcedX, y + i);
- }
- for(int i = 0; i <= r; i+=2){
- int calcedX = (int) Math.sqrt((r * r) - (i * i));
- drawMass(x-calcedX, y + i);
- }
- for(int i = 0; i <= r; i+=2){
- int calcedX = (int) Math.sqrt((r * r) - (i * i));
- drawMass(x-calcedX, y - i);
- }
- for(int i = 0; i <= r; i+=2){
- int calcedX = (int) Math.sqrt((r * r) - (i * i));
- drawMass(x+calcedX, y - i);
- }
- }
- }
- private static void drawFunction(int xAxisScale, int yAxisScale){
- int i = 0;
- while(i * xAxisScale < canvWidth && function(i) * yAxisScale < canvHeight && i <= 100){
- drawMass(i * xAxisScale, function(i) * yAxisScale);
- i++;
- }
- }
- private static void clearScreen () {
- rob.mouseMove(clearBtnX, clearBtnY);
- click();
- }
- private static void click () {
- rob.mousePress(InputEvent.BUTTON1_DOWN_MASK);
- rob.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
- }
- private static void moveOnCanvas(int x, int y){
- if(!(x > canvWidth || y > canvHeight)) rob.mouseMove(topLeftCornX + x, topLeftCornY + y);
- }
- private static void waitForSeconds(double seconds){
- long startTime = System.currentTimeMillis();
- while(((double)(System.currentTimeMillis() - startTime))/1000 <= seconds) {
- //wait patiently
- }
- }
- private static int averageVal(int[] values){
- int addedVals = 0;
- for(int i = 0; i < values.length; i++){
- addedVals += values[i];
- }
- return addedVals / values.length;
- }
- private static void typeNumber(int n){
- char[] ca = String.valueOf(n).toCharArray();
- for(char c : ca){
- typeNumberKey(c);
- }
- }
- private static void typeNumberKey(char n){
- switch(n){
- case '0':
- rob.keyPress(KeyEvent.VK_0);
- rob.keyRelease(KeyEvent.VK_0);
- break;
- case '1':
- rob.keyPress(KeyEvent.VK_1);
- rob.keyRelease(KeyEvent.VK_1);
- break;
- case '2':
- rob.keyPress(KeyEvent.VK_2);
- rob.keyRelease(KeyEvent.VK_2);
- break;
- case '3':
- rob.keyPress(KeyEvent.VK_3);
- rob.keyRelease(KeyEvent.VK_3);
- break;
- case '4':
- rob.keyPress(KeyEvent.VK_4);
- rob.keyRelease(KeyEvent.VK_4);
- break;
- case '5':
- rob.keyPress(KeyEvent.VK_5);
- rob.keyRelease(KeyEvent.VK_5);
- break;
- case '6':
- rob.keyPress(KeyEvent.VK_6);
- rob.keyRelease(KeyEvent.VK_6);
- break;
- case '7':
- rob.keyPress(KeyEvent.VK_7);
- rob.keyRelease(KeyEvent.VK_7);
- break;
- case '8':
- rob.keyPress(KeyEvent.VK_8);
- rob.keyRelease(KeyEvent.VK_8);
- break;
- case '9':
- rob.keyPress(KeyEvent.VK_9);
- rob.keyRelease(KeyEvent.VK_9);
- break;
- default:
- System.out.println("Use typeNumber(int n) for numbers larger than 9!");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement