I'm trying to sort through a TPA and remove a point if it matches a color within a certain tolerance. I tried doing it manually with a few loops but that didn't work, and I don't see anything in the wizzyplugin that would help me out. Any ideas?
n = integer
for i := 0 to high(array) do
begin
if not array.color is somehow(within tolerance) then n = n + 1;
newarray[n] = array[i]
end
something to that extent if it made sense, just have a loop with another integer in it that will have index for a new array which will replace the old one
Simba Code:function RemoveLikeColorsTPA(Color, Tolerance: Integer; TPA: TPointArray): TPointArray;
var
NewArray: TPointArray;
i, Index, Hi, Color1: Integer;
begin
if Length(TPA) < 1 then Exit;
SetLength(NewArray, Length(TPA));
Hi := High(TPA);
Index := 0;
for i := 0 to Hi do
begin
Color1 := GetColor(TPA[i].x, TPA[i].y);
if not SimilarColors(Color1, Color, Tolerance) then
begin
NewArray[Index] := TPA[i];
Inc(Index);
end;
end;
SetLength(NewArray, Index);
Result := NewArray;
end;
Edit: read the first post wrong.
Last edited by mormonman; 01-23-2011 at 11:33 PM.
Should work?Simba Code:function RemoveLikeColorsTPA(Color, Tolerance: Integer; TPA: TPointArray): TPointArray;
var
NewArray: TPointArray;
i, Index, h, Color1: Integer;
begin
if Length(TPA) < 1 then
exit;
h := High(TPA);
for i := 0 to h do
begin
:= GetColor(TPA[i].x, TPA[i].y);
if SimilarColors(Color, GetColor(TPA[i].x, TPA[i].y), Tolerance) then
begin
swap(TPA[High(TPA)], TPA[i]);
SetArrayLength(TPA, GetArrayLength(TPA - 1));
end;
end;
Result := TPA;
end;
Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
Originally Posted by #srl
"A programmer is just a tool which converts caffeine into code"
Simba Code:function RemoveLikeColorsTPA(Color, Tolerance: Integer; TPA: TPointArray): TPointArray;
var
cols: TIntegerArray;
i, h, L: Integer;
begin
if Length(TPA) < 1 then
exit;
h := High(TPA);
SetLength(Result, h+1);
cols := getColors(TPA);
L := 0;
for i := 0 to h do
begin
if (not SimilarColors(Color, cols[i], Tolerance)) then
begin
// if the colour is not similar, add the index into the array.
Result[L] := TPA[i];
Inc(L);
end;
SetLength(Result, L);
end;
Should be significantly faster then others posted.
Only grabs the client ONCE, rather than every time. Also, it does not do memory management every time a colour is valid, instead it only allocates then copies it over once.
Writing an SRL Member Application | [Updated] Pascal Scripting Statements
My GitHub
Progress Report:13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you have serious physchological problems 13:46 <@BenLand100> HE GETS IT! 13:46 <@BenLand100> HE FINALLY GETS IT!!!!1
To use this practically you'd have to do it like this:
SCAR Code:{.include SRL/SRL.scar}
{.include SRL/SRL/misc/debug.scar}
type
TColorPointArray = record
Points: TPointArray;
Colors: TIntegerArray;
end;
function FindTCPA(var TCPA: TColorPointArray; Color, xs, ys, xe, ye, Tol: Integer): Boolean;
begin
Result := FindColorsTolerance(TCPA.Points, Color, xs, ys, xe, ye, Tol);
if (not (Result)) then
Exit;
TCPA.Colors := GetColors(TCPA.Points);
end;
function RemoveColorsInTPA(TCPA: TColorPointArray; Color: LongInt): TColorPointArray;
var
H, I, L: LongInt;
begin
H := High(TCPA);
for I := 0 to H do
if (TCPA.Colors[I] <> Color) then
begin
Inc(L);
SetLength(Result, L);
Result.Points[L - 1] := TCPA.Points[I];
Result.Colors[L - 1] := TCPA.Colors[I];
end;
end;
function RemoveColorsInTPATol(TCPA: TColorPointArray; Color, Tol: LongInt): TColorPointArray;
var
H, I, L: LongInt;
begin
H := High(TCPA);
for I := 0 to H do
if (not (SimilarColors(TCPA.Colors[I], Color, Tol))) then
begin
Inc(L);
SetLength(Result, L);
Result.Points[L - 1] := TCPA.Points[I];
Result.Colors[L - 1] := TCPA.Colors[I];
end;
end;
var
TCPA: TColorPointArray;
begin
SetUpSRL;
ActivateClient;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.2, 0.2);
FindTCPA(TCPA, 12344556, MSX1, MSY1, MSX2, MSY2, 5);
RemoveColorsInTPATol(TCPA, 1235932, 5);
SetColorspeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(1);
DebugTPA(TCPA.Points, '');
end.
Writing an SRL Member Application | [Updated] Pascal Scripting Statements
My GitHub
Progress Report:13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you have serious physchological problems 13:46 <@BenLand100> HE GETS IT! 13:46 <@BenLand100> HE FINALLY GETS IT!!!!1
Well you ninja'd me technically.
But really a TPA is only a recording of points, if you take the same points and apply it to a TPA of a different time period in coordination with getcolors you're not working with the original colors, it's important to record the colors at the same time you record the points, hence the purpose of TColorPointArray and FindTCPA.
This is true, but for the purpose I would be using it for I would using it for, the objects (bankers) don't move. So, under normal circumstances, yes yours would be better, but I'll probably use one of the other, less script-bloating solutions.
Edit:
Also, I meant to post this before I left but i guess i missed the "submit reply" button
Simba Code:function FilterPointsColorTolerance(Color, Tolerance: LongInt; TPA: TPointArray): TPointArray;
var
i, j, x, y: Integer;
begin
for i := 0 to High(TPA) do
if not(FindColorTolerance(x, y, Color, TPA[i].x, TPA[i].y, TPA[i].x, TPA[i].y, Tolerance)) then
begin
SetLength(Result, Length(Result) + 1);
Result[High(Result)] := TPA[i];
end;
end;
Tom, yours really is much slower and if the TPA is big it'll lag.
+ rep to Nava & Ice
~RM
There are currently 1 users browsing this thread. (0 members and 1 guests)