usefull RS functions ins JAVA

Discussion in 'Programming General' started by slashshot007, Nov 22, 2007.

usefull RS functions ins JAVA
  1. Unread #1 - Nov 22, 2007 at 8:18 AM
  2. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    usefull RS functions ins JAVA

    Movemouse Smooth:
    yeah.. credits go to flaming idiots for the code, i just converted it to java.
    heres the import statements needed:
    Code:
    import java.awt.*;
    and heres the code
    Code:
    	public void SmoothMove(Point Destination, double Speed){
       		try {
    	   		Robot robot = new Robot();
    	   		PointerInfo PInfo = MouseInfo.getPointerInfo();
    			Point origin = PInfo.getLocation();
    	   		Point Difference = new Point((int)(Destination.getX() - PInfo.getLocation().getX()),(int)(Destination.getY() - PInfo.getLocation().getY()));				
    			for(double Current = 0; Current < 1; Current+= (Speed/Math.sqrt(Math.pow(Difference.getX(),2) + Math.pow(Difference.getY(),2)))){
    				PInfo = MouseInfo.getPointerInfo();
    				robot.mouseMove((int)origin.getX() + (int)(Difference.getX() * Current),(int)origin.getY() + (int)(Difference.getY() * Current););
    				robot.setAutoDelay(3);
    			}
    			}catch(java.awt.AWTException exc) {
    				System.out.println("error");
    			}	
    	}
    findColor
    I made a basic findColor function - it probably could be done in less code, but i'm too lazy to try and fingure it out so this is what you're stuck with unless you know how to change it. It returns a Point if you can't figure that out from the code.
    if it cannot find the color in the rectangle, it will return the point as x = -1, y = -1

    x1 is the x coordinate of the upper left point of the Rectangle that will be searched. y1 is the y coordinate.
    x2 is the x coordinate of the bottom right point of the Rectangle, and y2 is the Y coordinate.

    heres the import statements needed:
    Code:
    import java.awt.*;
    and heres the code:
    Code:
    	private static Point findColor(Color color, int x1, int y1, int x2, int y2){
    		try {
    			Robot robot = new Robot();
    			for(int x = x1; x<x2; x++)
    				for(int y = y1; y<y2;y++)
    					if(robot.getPixelColor(x,y).equals(color))
    						return new Point(x,y);
    		}catch(java.awt.AWTException exc) {
    			return new Point(-1,-1);
    		}
    		return new Point(-1,-1);
    	}
    EDIT:I updated the findcolor code DRASTICALLY. Now is much more efficient. still does everything the same way though.

    EDIT AGAIN:
    ok i found a much more efficient method, i've been told that getPixelColor can get very slow so heres a much faster way:
    usage remains the same
    Code:
    	private static Point findColor(Color color, int x1, int y1, int x2, int y2){
    		try {
    			Robot robot = new Robot();
    			BufferedImage image = robot.createScreenCapture(new Rectangle(x1-1,y1-1,Math.abs(x1-x2)+1,Math.abs(y1-y2)+1));
    			int colorint = color.getRGB();
    			for(int y = 0; y < y2-y1; y++)
    				for(int x = 0; x < x2-x1 ; x++)
    					if(image.getRGB(x,y)==colorint){					
    						return new Point(x+x1,y+y1);
    		}catch(java.awt.AWTException exc) {
    			return new Point(-1,-1);
    		}
    		return new Point(-1,-1);
    	}
     
  3. Unread #2 - Nov 22, 2007 at 12:00 PM
  4. timk777
    Joined:
    Feb 19, 2007
    Posts:
    156
    Referrals:
    0
    Sythe Gold:
    0

    timk777 Active Member

    usefull RS functions ins JAVA

    Nice work Slashshot. Haven't talked to you in a while. Keep up the good work though. I'm glad to see people still using Java besides Moparscape.
     
  5. Unread #3 - Nov 22, 2007 at 1:06 PM
  6. speljohan
    Joined:
    Apr 24, 2005
    Posts:
    1,450
    Referrals:
    3
    Sythe Gold:
    0

    speljohan Guru
    Visual Basic Programmers

    usefull RS functions ins JAVA

    These could be useful for some people, too bad nobody here is interested in Java :/
     
  7. Unread #4 - Dec 4, 2007 at 9:23 PM
  8. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    usefull RS functions ins JAVA

    I am interseted in Java. And i have been looking for something like this cuz I am very lazy to write my own code XD
     
  9. Unread #5 - Dec 4, 2007 at 9:53 PM
  10. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    usefull RS functions ins JAVA

    be sure to give credit SuF

    and also i updated the FindColor so its ALOT smaller, but still can be used the same way, and is still done the same way.
     
  11. Unread #6 - Dec 5, 2007 at 1:17 PM
  12. isosceles
    Joined:
    Jan 22, 2007
    Posts:
    455
    Referrals:
    0
    Sythe Gold:
    0

    isosceles Forum Addict
    $5 USD Donor

    usefull RS functions ins JAVA

    Thanks, very helpful.

    I have been fooling around with the robot class lately, and this should prove useful.
     
  13. Unread #7 - Dec 23, 2007 at 5:43 PM
  14. rscheater13
    Referrals:
    0

    rscheater13 Guest

    usefull RS functions ins JAVA

    Nice. I started writing the SendKeys method, but it's being a pain in the butt. You might wanna add that, as it can be easier than keyPress keyRelease
     
  15. Unread #8 - Dec 25, 2007 at 8:23 AM
  16. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    usefull RS functions ins JAVA

    http://www.sythe.org/showthread.php?t=304438
     
  17. Unread #9 - Dec 26, 2007 at 9:42 AM
  18. Big Knockers
    Joined:
    Oct 8, 2007
    Posts:
    72
    Referrals:
    0
    Sythe Gold:
    0

    Big Knockers Member
    Banned

    usefull RS functions ins JAVA

    Pretty helpful. Thank for saying



    -Big Knockers
     
  19. Unread #10 - Jan 5, 2008 at 1:22 PM
  20. Shlorine
    Referrals:
    0

    Shlorine Guest

    usefull RS functions ins JAVA

    btw that buldozer in your avy, it isnt original SCAR its Autorune.

    Shit
    Compare To
    Auto
    Rune
     
  21. Unread #11 - Feb 6, 2008 at 6:04 AM
  22. _3x6
    Joined:
    Dec 23, 2007
    Posts:
    232
    Referrals:
    0
    Sythe Gold:
    0

    _3x6 Active Member
    Banned

    usefull RS functions ins JAVA

    is it scar or not?
     
< java 1.6 for mac | problems with java autominer >

Users viewing this thread
1 guest


 
 
Adblock breaks this site