[source] FindColorSpiral

Discussion in 'Programming General' started by slashshot007, Dec 27, 2007.

[source] FindColorSpiral
  1. Unread #1 - Dec 27, 2007 at 8:46 PM
  2. slashshot007
    Joined:
    May 6, 2006
    Posts:
    164
    Referrals:
    0
    Sythe Gold:
    0

    slashshot007 Active Member

    [source] FindColorSpiral

    credits to cruel again, i just converted it to java. Winter break really got me bored, so i'm just converting stuff from language to language :p.
    Code:
    	public Point FindColorSpiral(Color color, Point StartPoint, Rectangle SearchArea){
    		//Credits to Cruel for this, SlashShot only converted it to Java
    		try{
    			Robot robot = new Robot();
    			BufferedImage image = robot.createScreenCapture(SearchArea);
    	   	 	int x = (int)StartPoint.getX() - (int)SearchArea.getX();
    				int y = (int)StartPoint.getY() - (int)SearchArea.getY();
    			int direction = 0, length = 1;
    			int rgbcolor = color.getRGB();
    			if (rgbcolor == image.getRGB(x, y))
    				return new Point((int)SearchArea.getX() + x, (int)SearchArea.getY() + y);
    			while ((x > 2) && (y > 2) && (x < SearchArea.getWidth() - 2) && (y < SearchArea.getHeight() - 2)){
    				for (int i = 1; i <= length; i++){
    					switch(direction){
    						case 0 :
    							y = y - 1;
    							break;
    						case 1 : 
    							x = x + 1;
    							break;
    						case 2 : 
    			   			 	y = y + 1;
    				   	 		break;
    						case 3 : 
    							x = x - 1;
    							break;
    					}
    					if (rgbcolor == image.getRGB(x, y))
    						return new Point((int)SearchArea.getX() + x, (int)SearchArea.getY() + y);
    				}	
    				direction = (direction + 1) % 4;
    				if ((direction % 2) == 0) 
    					length = length + 1;
    			}	
    			return new Point(-1, -1);
    		}catch(java.awt.AWTException exc) {
    			return new Point(-1,-1);
    		}
    	}
     
< do you guys HATE account scammers as much as i do? | a little delima >

Users viewing this thread
1 guest


 
 
Adblock breaks this site