Added getRect()
This commit is contained in:
parent
ae521ece46
commit
724d5c51ea
|
@ -46,7 +46,7 @@ public class Clicker implements Runnable{
|
|||
private void sleep( int ms) {
|
||||
//update ui
|
||||
Main.get().ui.printTime((int) ( (System.currentTimeMillis()-started) / 1000 ));
|
||||
|
||||
|
||||
if(skipbattle)
|
||||
return;
|
||||
try {
|
||||
|
@ -324,22 +324,22 @@ public class Clicker implements Runnable{
|
|||
return false;
|
||||
//long start = System.currentTimeMillis();
|
||||
int count = 0;
|
||||
BufferedImage img = bot.createScreenCapture(new Rectangle(p.x-10, p.y-10, 20, 20));//smile
|
||||
for (int x = 0; x < 20; x++) {
|
||||
for (int y = 0; y < 20; y++) {
|
||||
BufferedImage img = bot.createScreenCapture(getRect(p.x, p.y));//smile
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
int color = img.getRGB(x, y);
|
||||
int red = (color & 0x00ff0000) >> 16;
|
||||
int green = (color & 0x0000ff00) >> 8;
|
||||
int blue = color & 0x000000ff;
|
||||
double distance = Math.sqrt(Math.pow((blue - goalcolor.getBlue()), 2)
|
||||
int green = (color & 0x0000ff00) >> 8;
|
||||
int blue = color & 0x000000ff;
|
||||
double distance = Math.sqrt(Math.pow((blue - goalcolor.getBlue()), 2)
|
||||
+ Math.pow((red - goalcolor.getRed()), 2) + Math.pow((green - goalcolor.getGreen()), 2));//calculate the distance between the goalcolor and the test color
|
||||
if (distance < mincolordistance)
|
||||
count++;
|
||||
if (distance < mincolordistance)
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
// System.out.println("counts: " + count);//some performance checking
|
||||
return count > 70;
|
||||
return count > 4;//engough pixel have the right color
|
||||
}
|
||||
|
||||
public Point getMouse() {
|
||||
|
@ -396,6 +396,10 @@ public class Clicker implements Runnable{
|
|||
unsupported
|
||||
}
|
||||
|
||||
|
||||
public static Rectangle getRect(int x, int y) {
|
||||
return new Rectangle(x-2, y-2, 5, 5);
|
||||
}
|
||||
|
||||
public void toggleOverlay() {
|
||||
if(ov == null) {
|
||||
|
|
|
@ -2,7 +2,6 @@ package mrbesen.cr.auto.clicker;
|
|||
|
||||
import java.awt.AWTException;
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Robot;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.util.Comparator;
|
||||
|
@ -24,7 +23,7 @@ public class PosColSelector extends PosSelector {
|
|||
try {
|
||||
Robot rob = new Robot();
|
||||
Point p = ui.bot.getMouse();
|
||||
BufferedImage img = rob.createScreenCapture(new Rectangle(p.x-10, p.y-10, 20, 20));
|
||||
BufferedImage img = rob.createScreenCapture(Clicker.getRect(p.x, p.y));
|
||||
//calculate avg color;
|
||||
int red = 0;
|
||||
int green = 0;
|
||||
|
@ -46,8 +45,8 @@ public class PosColSelector extends PosSelector {
|
|||
|
||||
//calculate distances:
|
||||
List<Integer> dist = new LinkedList<Integer>();
|
||||
for (int x = 0; x < 20; x++) {
|
||||
for (int y = 0; y < 20; y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
int color = img.getRGB(x, y);
|
||||
int redf = (color & 0x00ff0000) >> 16;
|
||||
int greenf = (color & 0x0000ff00) >> 8;
|
||||
|
|
|
@ -62,7 +62,7 @@ public class UI implements ActionListener {
|
|||
private JButton skip = new JButton("SKIP"); // the button, to skip waiting
|
||||
private JButton pause = new JButton("Pause");
|
||||
private JButton exit = new JButton("EXIT");
|
||||
private JButton overlay = new JButton("Overlay");
|
||||
private JButton overlay = new JButton("Overlay[Experimental]");
|
||||
|
||||
private JLabel info = new JLabel("Define positions, to start.");
|
||||
private JLabel time = new JLabel("0 s");
|
||||
|
|
Loading…
Reference in New Issue