All pastes #415495 Raw Edit

Someone

public text v1 · immutable
#415495 ·published 2007-03-29 17:53 UTC
rendered paste body
public XY findColorSpiral(Rectangle where, IColor color, int tol)
	{
		IMap client = getClient(where);
		
		
		int direction = 0;
		int length = 1;
		
		int centerx = ((int)client.w) / 2;
		int centery = ((int)client.h) / 2;
		
		int x = centerx;
		int y = centery;
		
		if(tolerant(client.image[x][y], color, tol)) return new XY(where.x + x, where.y + y);
		
		do
		{
			for(int i = 0; i < length; i++)
			{
				if(direction == 0) y = y - 1;
				if(direction == 1) x = x + 1;
				if(direction == 2) y = y + 1;
				if(direction == 3) x = x - 1;
				
				if(x > 0 && y > 0 && x < client.w && y < client.h)
					if(tolerant(client.image[x][y], color, tol)) return new XY(where.x + x, where.y + y);
			}
			//SMMS(x, y);
			
			
			direction = (direction + 1) % 4;
			
			if((direction % 2) == 0 ) length = length + 1;
		}while(!((x < 0) || (y < 0) || (x > client.w) || (y > client.h)));
		
		if(x != -1 && y != -1) if(tolerant(client.image[x][y], color, tol)) return new XY(where.x + x, where.y + y);
		
		return null;
	}