I thought this might be useful, pretty much it finds a unique color on or around (like 3 pixels away) a given symbol. It first autocolors the symbol, then searches for the black around the symbol creating a Tbox, then gets all the colors in the Tbox and finds a unique color inside the box.
I found it works really well with Tree Symbols, and on symbols like Smithing that do not have one unique color, it gets a color right near it. Anyways, here's code (for some reasons its negating the spaces between Functions):
SCAR Code:
{*******************************************************************************
Function GetSymbolArea(Color: Integer; Hue, Sat: Extended; Tol: Integer): TPointArray;
By: Blumblebee
Description: Gathers Points of a particular color into a TPA Dependant on the Color,
Hue, Sat, and Tol provided.
*******************************************************************************}
Function GetSymbolArea(Color: Integer; Hue, Sat: Extended; Tol: Integer): TPointArray;
var TPA: TPointArray; ATPA: T2DPointArray; P: TPoint; l, i: integer;
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hue, Sat);
FindColorsSpiralTolerance(MMcx, MMcy, TPA, Color, MMx1, MMy1, MMx2, MMy2, Tol);
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
if Length(TPA) <= 0 then Exit;
ATPA := SplitTPAEx(TPA, 5, 5);
for i := 0 to High(ATPA) do
begin
P := MiddleTPA(ATPA[i]);
if rs_OnMiniMap(P.x,P.y) then
begin
l := getarraylength(Result);
SetArrayLength(Result, l+1);
Result[l] := P;
end;
end;
end;
{*******************************************************************************
Function CreateSymbolBox(TPA: TPointArray; TP: TPoint): TBox;
By: Blumblebee
Description: Creates a TBox around a cluster in a TPA. The TBox is created in
reference to the Black outside of the Symbol.
*******************************************************************************}
Function CreateSymbolBox(TPA: TPointArray; TP: TPoint): TBox;
var nTPA, oTPA: TPointArray;
begin
oTPA := TPA;
sortTPAFrom(oTPA, Point(TP.x, TP.y));
FindColorsTolerance(nTPA, 65536, oTPA[0].x-7, oTPA[0].y-7, oTPA[0].x+7, oTPA[0].y+7, 10);
if Length(nTPA) > 0 then
Result := GetTPABounds(nTPA);
end;
{*******************************************************************************
Function FindUniqueColors(Col: Integer; rTPA: TPointArray; Area: TPoint): Integer;
By: Blumblebee
Description: Gathers all Colors inside the "symbol box", and sorts for the most
unique color that is closest to the given color.
*******************************************************************************}
Function FindUniqueColors(Col: Integer; rTPA: TPointArray; Area: TPoint): Integer;
var SymBox: TBox; TPA: TPointArray; List1, List2, List3 : TIntegerArray; i, ii, Tol, L: integer;
begin
SymBox := CreateSymbolBox(rTPA, Area);
FindColorsTolerance(TPA, 0, SymBox.x1, SymBox.y1, SymBox.x2, SymBox.y2, 225);
List1 := GetColors(TPA);
List2 := List1;
ClearSameIntegers(List1);
for i := 0 to High(List2) do
begin
for ii := 0 to High(List1) do
begin
if List1[ii] = List2[i] then
begin
L := getarraylength(List3);
SetArrayLength(List3, L+1);
List3[L] := List1[ii];
end;
end;
end;
Tol := 5;
while Result = 0 do
begin
for i := 0 to High(List3) do
begin
if SimilarColors(List3[i], Col, Tol) then
begin
Result := List3[i];
WriteLn('Unique Symbol Color = '+IntToStr(Result));
Exit;
end;
end;
IncEx(Tol, 1);
end;
end;
{*******************************************************************************
GetUniqueSymbolColor(x, y: Integer; Color: Integer; Hue, Sat: Extended; Tol: Integer): Integer;
By: Blumblebee
Description: Finds the most unique symbol color with the information given.
*******************************************************************************}
Function GetUniqueSymbolColor(x, y: Integer; Color: Integer; Hue, Sat: Extended; Tol: Integer): Integer;
begin
Result := FindUniqueColors(Color, GetSymbolArea(Color, Hue, Sat, Tol), Point(x, y));
end;
an example of using this would be as so:
SCAR Code:
var r, x, y: Integer;
begin
SetUpSRL;
r := GetUniqueSymbolColor(MMcx, MMy2, 229638, 0.17, 0.45, 15);
FindColor(x, y, r, MMx1, MMy1, MMx2, MMy2);
MMouse(x, y, 3, 3);
end.
debug reads:
Successfully compiled (3571 ms)
SRL Compiled in 16 msec
Unique Symbol Color = 494860
This works for the Tree Symbol in edgeville (as viewed from the bank).
There is an Area parameter (x, y) which allows the user to choose where the script searches from, so that if there is more than one of the same symbol on the MM, it will find the the closest to the point specified.
@Wizzup: I tried to impliment the sorting idea you showed me, but I found I recieved identical results to this one, so I left be.