TheGodfather
2007-04-21 01:38:34
Hey guys, this is my first crazy worth while function I think I've released here. I've released little ones but this is by far my best function ever.
Description:
This function here, searches for a given color in the given coordinates.
Why is this so special??
Well becuase, it's compatible with coordinates. Any coordinates. With the box that the coordinates create, this script splits it into 4 x 4 units. This makes 16 different boxes that it searches through, in a spiral motion clockwise, starting from the middle heading out.
This should make it so that it gets the coords of a color thats atleast somewhat close to the middle of the screen. Not always the closest one, but its never the furthest one.
Wrapped up within the 245 lines for this single function, it just may be useful. It's pretty easy to incorparate into w/e you're using (all you need is a color to look for and a box to look through).
Upcoming Releases:
- Tolerance (for everything)
- BitmapSearch (and a deformed search too)
- DtmSearch
- MultiColorSearch, (Looks for 3 colors close to eachother within givin pixels.)
- and many RS specealties. (SearchMMColor, ObjectSearch (with color, dtm, or bitmap) and much more…)
Post feedback please!
Oh, last but not least, the function itself!
quick sample way of using…
Description:
This function here, searches for a given color in the given coordinates.
Why is this so special??
Well becuase, it's compatible with coordinates. Any coordinates. With the box that the coordinates create, this script splits it into 4 x 4 units. This makes 16 different boxes that it searches through, in a spiral motion clockwise, starting from the middle heading out.
This should make it so that it gets the coords of a color thats atleast somewhat close to the middle of the screen. Not always the closest one, but its never the furthest one.
Wrapped up within the 245 lines for this single function, it just may be useful. It's pretty easy to incorparate into w/e you're using (all you need is a color to look for and a box to look through).
Upcoming Releases:
- Tolerance (for everything)
- BitmapSearch (and a deformed search too)
- DtmSearch
- MultiColorSearch, (Looks for 3 colors close to eachother within givin pixels.)
- and many RS specealties. (SearchMMColor, ObjectSearch (with color, dtm, or bitmap) and much more…)
Post feedback please!
Oh, last but not least, the function itself!
quick sample way of using…
ColorSearch(x, y, NPCdot, MMX1, MMY1, MMX2, MMY2);
{*******************************************************************************
function ColorSearch(var cx, cy: integer; Color, x1, y1, x2, y2: integer): Boolean;
By: TheGodfather
Description: Searches for a color through 16 sections, clockwise center out.
*******************************************************************************}
function ColorSearch(var cx, cy: integer; Color, x1, y1, x2, y2: integer): Boolean;
var
Midpoint, Temp: TPoint;
sx1, sx2, sy1, sy2, SearchBoxes: Integer;
begin
result := false;
if CountColor(Color, x1, y1, x2, y2) > 0 then
begin
Temp.x := x2 - x1;
Temp.x := Temp.x div 2;
Temp.y := y2 - y1;
Temp.y := Temp.y div 2;
Midpoint.x := x1 + Temp.x;
Midpoint.y := y1 + Temp.y;
Temp.x := Temp.x div 2;
Temp.y := Temp.y div 2;
for SearchBoxes := 1 to 16 do
begin
case SearchBoxes of
1: begin
sx1 := Midpoint.x;
sy1 := Midpoint.y;
sx2 := Midpoint.x + Temp.x;
sy2 := Midpoint.y + Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
2: begin
sx1 := Midpoint.x - Temp.x;
sy1 := Midpoint.y;
sx2 := Midpoint.x;
sy2 := Midpoint.y + Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
3: begin
sx1 := Midpoint.x - Temp.x;
sy1 := Midpoint.y - Temp.y;
sx2 := Midpoint.x;
sy2 := Midpoint.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
4: begin
sx1 := Midpoint.x;
sy1 := Midpoint.y - Temp.y;
sx2 := Midpoint.x + Temp.x;
sy2 := Midpoint.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
5: begin
sx1 := Midpoint.x + Temp.x;
sy1 := Midpoint.y - Temp.y;
sx2 := Midpoint.x + Temp.x * 2;
sy2 := Midpoint.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
6: begin
sx1 := Midpoint.x + Temp.x;
sy1 := Midpoint.y;
sx2 := Midpoint.x + Temp.x * 2;
sy2 := Midpoint.y + Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
7: begin
sx1 := Midpoint.x + Temp.x;
sy1 := Midpoint.y + Temp.y;
sx2 := Midpoint.x + Temp.x * 2;
sy2 := Midpoint.y + Temp.y * 2;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
8: begin
sx1 := Midpoint.x;
sy1 := Midpoint.y + Temp.y;
sx2 := Midpoint.x + Temp.x
sy2 := Midpoint.y + Temp.y * 2;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
9: begin
sx1 := Midpoint.x - Temp.x;
sy1 := Midpoint.y + Temp.y;
sx2 := Midpoint.x;
sy2 := Midpoint.y + Temp.y * 2;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
10: begin
sx1 := Midpoint.x - Temp.x * 2;
sy1 := Midpoint.y + Temp.y;
sx2 := Midpoint.x - Temp.x;
sy2 := Midpoint.y + Temp.y * 2;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
11: begin
sx1 := Midpoint.x - Temp.x * 2;
sy1 := Midpoint.y;
sx2 := Midpoint.x - Temp.x;
sy2 := Midpoint.y + Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
12: begin
sx1 := Midpoint.x - Temp.x * 2;
sy1 := Midpoint.y - Temp.y;
sx2 := Midpoint.x - Temp.x;
sy2 := Midpoint.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
13: begin
sx1 := Midpoint.x - Temp.x * 2;
sy1 := Midpoint.y - Temp.y * 2;
sx2 := Midpoint.x - Temp.x;
sy2 := Midpoint.y - Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
14: begin
sx1 := Midpoint.x - Temp.x;
sy1 := Midpoint.y - Temp.y * 2;
sx2 := Midpoint.x;
sy2 := Midpoint.y - Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
15: begin
sx1 := Midpoint.x;
sy1 := Midpoint.y + Temp.y * 2;
sx2 := Midpoint.x + Temp.x;
sy2 := Midpoint.y + Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
16: begin
sx1 := Midpoint.x + Temp.x;
sy1 := Midpoint.y + Temp.y * 2;
sx2 := Midpoint.x + Temp.x * 2;
sy2 := Midpoint.y + Temp.y;
if FindColorSpiral(x, y, Color, sx1, sy1, sx2, sy2) then
begin
result:= true;
cx := x;
cy := y;
Exit;
end;
end;
end;
end;
end;
end;