SRL Archive - SRL Archives

Saturn's function compilation!


lordsaturn

2008-09-29 02:51:50

Functions!

ContentsChangeLog:
(8/29)[INDENT]Initial release of functions.
Minor changes.
[/INDENT](8/30)[INDENT]Core->Text.scar
Edited FindArrayTextTPAEx.
Edited TrimString to be more versatile.
Added function ChooseOptionText.
Core->GameTab.scar
Edited CheckQuest due to changes in TrimString.
[/INDENT](11/28)[INDENT]Core->Text.scar
Improved FindTextArrayTPA(Ex)
Changed ChooseOptionText to ChooseOptionTPA and improved.
Core->GameTab.scar
Improved CheckQuest.
Added function GetQP.
[/INDENT](12/18)[INDENT]Reflection->Interfaces.scar
Added function GetQP.
[/INDENT](2/1)
[INDENT]Skill->WoodCutting.scar
Added functions IsEnt and IsEntText.
[/INDENT](2/15)
[INDENT]Core->MapWalk.scar
Added function GetWalls.
[/INDENT]

lordsaturn

2008-09-29 02:53:02

Core:





Colors.scar[INDENT]

{*******************************************************************************
procedure CaptureCTS(var CTS: integer);
By: lordsaturn
Description: Captures the ColorToleranceSpeed and stores to variable 'CTS'.
*******************************************************************************}
procedure CaptureCTS(var CTS: integer);
begin
CTS := GetColorToleranceSpeed;
end;


{*******************************************************************************
procedure RestoreCTS(CTS: integer);
By: lordsaturn
Description: Restores ColorToleranceSpeed 'CTS' and default ColorSpeed2Modifiers.
*******************************************************************************}
procedure RestoreCTS(CTS: integer);
begin
if GetColorToleranceSpeed = 2 then
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
end;

{*******************************************************************************
function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
By: lordsaturn
Description: Finds all colors of TIntegerArray 'Colors' in the area specified by
xs, ys, xe, ye and returns their coordinates in T2DPA 'ResultTPA'. Will return
True if all colors are found.
*******************************************************************************}
function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
var
i, LTIA: integer;

begin
if Length(Colors) = 0 then Exit;
Result := True;
LTIA := Length(Colors) - 1;
for i := 0 to LTIA do
if not FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol) then
Result := False;
end;


{*******************************************************************************
function FindColorsArraySpiralTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
By: lordsaturn
Description: Same as FindColorsArrayTolerance, but uses spiral technique.
*******************************************************************************}
function FindColorsArraySpiralTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
var
i, LTIA: integer;
MP: TPoint;

begin
if Length(Colors) = 0 then Exit;
Result := True;
LTIA := Length(Colors) - 1;
MP := MidPoint(xs, ys, xe, ye);
for i := 0 to LTIA do
begin
FindColorsSpiralTolerance(MP.x, MP.y, ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
if Length(ResultTPA[i]) = 0 then
Result := False;
end;
end;
[/INDENT]





GameTab.scar[INDENT]

{*******************************************************************************
function CheckQuest(Quest: string): Boolean;
By: lordsaturn
Description: Will return true if the quest 'Quest' is completed, and perform the
action declared in 'Action'.
*******************************************************************************}
function CheckQuest(Quest: string; Action: fnct_ActionOptions): Boolean;
var
arS: TStringArray;
arI: TIntegerArray;
x, y, fx, fy, i, c, fColor, WT, L: Integer;
UltiBool: Boolean;
begin
arS := TrimString(Quest);
L := Length(arS) - 1;
for i := 0 to L do
begin
if arS[i] = 'i' then arS[i] := 'II';
if arS[i] = 'okt' then arS[i] := 'ok';
end;
arI := [65280, 65535, 255];
GameTab(3);
while not UltiBool do
begin
c := c + 1;
if c = 2 then
if GetColor(728, 245) <> 1316634 then
Mouse(728, 250, 4, 4, True);
if c = 3 then
begin
MMouse(728, 446, 5, 5);
GetMousePos(x, y);
HoldMouse(x, y, True);
end;
if GetColor(728, 419) = 1316634 then
begin
Writeln('We could not find the quest name.');
Result := False;
Exit;
end;
for i := 0 to 2 do
begin
UltiBool := FindTextArrayTPAEx(arI[i], 0, 547, 227, 720, 454, fx, fy, arS, StatChars, 140, 13);
if UltiBool then
begin
arI[i] := fColor;
Break;
end;
end;
end;
if UltiBool then
begin
if c > 2 then
begin
WT := 100+Random(700);
Wait(WT); //for randomization
ReleaseMouse(x, y, True);
end;
if fColor = arI[0] then
Result := True;
if Action = Nothing then Exit;
if WT > 0 then fy := fy - (WT/5) - 11;
MMouse(fx, fy, 4, 4);
if not FindTextArrayTPA(16777215, 0, 547, 227, 720, 454, arS, StatChars) then
begin
for i := 0 to 2 do
if FindTextArrayTPAEx(arI[i], 0, 547, 227, 720, 454, fx, fy, arS, StatChars, 140, 13) then
Break;
if i = 3 then Exit;
MMouse(fx, fy, 4, 4);
end;
if Action = Move then Exit;
GetMousePos(fx, fy);
case Action of
ClickLeft: Mouse(fx, fy, 0, 0, True);
ClickRight: begin
Mouse(fx, fy, 0, 0, False);
ChooseOption('ead');
end;
end;
MouseBox(455, 66, 474, 84, 1);
//CloseWindows;
end;
end;

{*******************************************************************************
function GetQP: Integer;
By: lordsaturn
Description: Will return number of quest points.
*******************************************************************************}
function GetQP: Integer;
var
x, y: integer;
s: string;
begin
if GetCurrentTab <> 3 then GameTab(3);
if FindColor(x, y, 2070763, 650, 205, 712, 226) then
begin
s := Trim(GetTextAtEx(x - 2, y - 2, 5, SmallChars, False, False, 0, 1, 2070763, 3, False, tr_AllChars));
try
Result := StrToInt(s);
except
if Pos('g', Lowercase(s)) <> 0 then
begin
s := Uppercase(ReplaceRegex(Lowercase(s), 'g', '6'));
try
Result := StrToInt(s);
except
writeln('GetQP failed and got: '+s);
end;
end;
end;
end;
end;
[/INDENT]



MapWalk.scar[INDENT]

{*******************************************************************************
function GetWalls: TPointArray;
By: lordsaturn
Description: Will return all the white-colored walls on the minimap in a TPA.
Could be used for perfect map aligning projects.
*******************************************************************************}
function GetWalls: TPointArray;
var
CTS, Hi, i, x, y, c, j: integer;
P, Playerses: TPointArray;
begin
if not LoggedIn then Exit;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorspeed2Modifiers(15.75, 5.27); // 15462126
FindColorsSpiralTolerance(MMCX, MMCY, P, 15593449, MMX1, MMY1, MMX2, MMY2, 7);
SetColorspeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(1);
FindColorsTolerance(Playerses, 16711422, MMX1, MMY1, MMX2, MMY2, 19);
ColorToleranceSpeed(2);
P := RemoveDistTPointArray(MMCX, MMCY, 76, P, True);
P := ClearTPAFromTPA(P, Playerses);
Hi := High(P);
for j := 0 to 2 do
for i := 0 to Hi do
begin
x := P[i].x;
y := P[i].y;
c := GetColor(x-1, y);
if ((GetColor(x-2, y) = c) and (GetColor(x-1, y-1) = c) and
(GetColor(x-2, y-1) = c) and (GetColor(x, y+2) = 65536)) or
((c = 65536) and ((GetColor(x, y+1) = c) or (GetColor(x+2, y) = c))) or
(GetColor(x, y+1) = 12961221) or (GetColor(x, y+1) = 13816530) then
begin
P := RemoveDistTPointArray(x, y, 2, P, False);
Hi := High(P);
end;
end;
Result := P;
end;
[/INDENT]



Math.scar[INDENT]

{*******************************************************************************
function MidPoint(x1, y1, x2, y2: integer): TPoint;
By: lordsaturn
Description: Will return the midpoint of two points as a TPoint.
*******************************************************************************}
function MidPoint(x1, y1, x2, y2: integer): TPoint;
var
mx, my: integer;
mmx, mmy: extended;
P: TPoint;

begin
mx := x1 + x2;
my := y1 + y2;
mmx := mx / 2;
mmy := my / 2;
P := Point(Round(mmx), Round(mmy));
Result := P;
end;
Same as:

MiddleTPA([inttopoint(x1, y1), inttopoint(x2, y2)]);
[/INDENT]





Text.scar[INDENT]

{*******************************************************************************
function FindTextArrayTPAEx(Color, Tol, xs, ys, xe, ye: integer; var x, y :integer; TextArray: TStringArray; Chars, MaxDist: integer; Action: fnct_ActionOptions; var Bools: array of Boolean): Boolean;
By: lordsaturn
Description: Like FindTextTPAEx, but finds an array of text, declared by
'TextArray'. Returns true if all instances of the TextArray are found within box
defined by distance boundaires 'w' and 'h'.
*******************************************************************************}
function FindTextArrayTPAEx(Color, Tol, x1, y1, x2, y2: integer; var x, y :integer; TextArray: TStringArray; Chars, w, h: integer): Boolean;
var
TextTPA, SearchTPA, tmpMatches: TPointArray;
SearchT2D: T2DPointArray;
i, j, Height, LATPA, LTSA: integer;
foundInDist: Boolean;
begin
if not FindColorsTolerance(SearchTPA, Color, x1, y1, x2, y2, Tol) then Exit;
SearchT2D := TPAtoATPAEx(SearchTPA, w, h);
LATPA := High(SearchT2D);
LTSA := Length(TextArray) - 1;
for i := 0 to LATPA do
begin
for j := 0 to LTSA do
begin
TextTPA := LoadTextTPA(TextArray[j], Chars, Height);
foundInDist := FindTextTPAinTPA(Height, TextTPA, SearchT2D[i], tmpMatches);
if not foundInDist then Break;
end;
if foundInDist then Break;
end;
if foundInDist then
begin
Result := True;
MiddleTPAEx(SearchT2D[i], x, y);
end;
end;


{*******************************************************************************
FindTextArrayTPA(Color, Tol, xs, ys, xe, ye: integer; TextArray: TStringArray; Chars: integer): Boolean;
By: lordsaturn
Description: Like FindTextArrayTPAEx, but has no distance restriction, and will
only return a boolean statement.
*******************************************************************************}
function FindTextArrayTPA(Color, Tol, xs, ys, xe, ye: integer; TextArray: TStringArray; Chars: integer): Boolean;
var
cx, cy: integer;
begin
Result := FindTextArrayTPAEx(Color, Tol, xs, ys, xe, ye, cx, cy, TextArray, Chars, xe-xs, ye-ys);
end;

{*******************************************************************************
function TrimString(TString: string): TStringArray;
By: lordsaturn
Description: Trims a string into an array of short 3-character strings.
Used in CheckQuest, ChooseOptionText.
*******************************************************************************}
function TrimString(TString: string): TStringArray;
var
i, P, L: integer;
S, S2: string;
arS: TStringArray;
begin
S := Trim(TString);
S := Lowercase(S);
S := Replace(S, '''', ' ');
S := Replace(S, '-', ' ');
arS := strToStrArray(S);
L := Length(arS) - 1;
for i := 0 to L do
begin
arS[i] := Trim(arS[i]);
if Pos('.', arS[i]) <> 0 then
Delete(arS[i], P, Length(arS[i])-P+1);
arS[i] := Replace(arS[i], '&', '');
if (Length(arS[i]) = 1) then arS[i] := '';
if (not(arS[i] = 'of')) and
(not(arS[i] = 'to')) then
arS[i] := Trim(Copy(arS[i], 2, 3));
if arS[i] <> '' then
S2 := S2+' '+arS[i]; //rebuilding the TSA to remove blank indexes
end;
S2 := Trim(S2);
Result := strToStrArray(S2);
end;

{*******************************************************************************
function ChooseOptionTPA(Option: string): Boolean;
By: lordsaturn
Description: Chooses an option using TPAs. Returns true if found. Use full text
string for best results. Ex: ChooseOptionTPA('Talk-to Sir Vant');
ChooseOptionTPA('Chop down Oak');
*******************************************************************************}
function ChooseOptionTPA(Option: string): Boolean;
var
x, y, i, c: Integer;
TPA: TPointArray;
P: TPoint;
B: TBox;
s: TStringArray;
begin
GetClientDimensions(B.X2, B.Y2);
B.X1 := 0;
B.Y1 := 0;
FindColorsTolerance(TPA, 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
If Length(TPA) < 10 Then
Exit;
B.X2 := 0;
B.Y2 := 0;

P := TPA[0];
For I := 0 To High(TPA) - 1 Do
If TPA[i].X = TPA[I+1].X - 1 Then
Begin
If C > 5 Then
Begin
B.X1 := P.X;
B.Y1 := P.Y;
Break;
End Else
C := C + 1;
End
Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;
InvertTPA(TPA);
C := 0;
P := TPA[0];
For I := 0 To High(TPA) - 1 Do
If TPA[i].X = TPA[I+1].X + 1 Then
Begin
If C > 5 Then
Begin
B.X2 := P.X;
B.Y2 := P.Y;
Break;
End Else
C := C + 1;
End Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;

s := TrimString(Option);
Result := FindTextArrayTPAEx(16777215, 255, B.x1, B.y1, B.x2, B.y2, x, y, s, UpChars, B.x2-B.x1, 14);
if Result then
if (x <> 0) and (y <> 0) then
begin
Mouse(x, y, (Length(Option)*5)/2, 3, True);
Exit;
end;
Result := ChooseOptionMulti(s);
end;


Useless, but works:

{*******************************************************************************
function LoadTextArrayTPA(TextArray: TStringArray; chars: integer; var Height: TIntegerArray): T2DPointArray;
By: lordsaturn
Description: Loads TPAs of the TStringArray 'TextArray'. Returns the TPAs in a
T2DPointArray corresponding to the indexes of TextArray. Also returns the
TIntegerArray 'Height' with indexes corresponding to TextArray.
*******************************************************************************}
function LoadTextArrayTPA(TextArray: TStringArray; chars: integer; var Height: TIntegerArray): T2DPointArray;
var
DC: HDC;
CTS, w, h, BMP, i: Integer;

begin;
if Length(TextArray) = 0 then Exit;
DC := GetClientCanvas.Handle;
CaptureCTS(CTS);
ColorToleranceSpeed(0);
for i := 0 to Length(TextArray) - 1 do
begin
BMP := CreateBitmapMaskFromText(TextArray[i], Chars);
GetBitmapSize(BMP, W, H);
SetTargetDc(GetBitmapDc(BMP));
FindColorsTolerance(Result[i], clwhite, 0, 0, w+1, h+1, 0);
Height[i] := h - 1;
FreeBitmap(BMP);
end;
SetTargetDC(DC);
RestoreCTS(CTS);
end;
[/INDENT]

lordsaturn

2008-09-29 02:54:13

Misc:





WizzyPlugin.scar..?
[INDENT]

{*******************************************************************************
function RemoveMultiDistTPA(x, y, w, h: Integer; ThePoints: TPointArray; Sort: Boolean): TPointArray;
By: lordsaturn
Description: Like RemoveDistTPointArray, but multi-dimensional. Will sort if true.
*******************************************************************************}
function RemoveMultiDistTPA(x, y, w, h: Integer; ThePoints: TPointArray; Sort: Boolean): TPointArray;
var
tmpDistX, tmpDistY, i, LTPA: integer;
begin
LTPA := Length(ThePoints) - 1;
for i := 0 to LTPA do
begin
tmpDistX := iAbs(ThePoints[i].x - x);
tmpDistY := iAbs(ThePoints[i].y - y);
if w <> 0 then
if (tmpDistX >= w) then
begin
TPARemove(ThePoints, i);
LTPA := LTPA - 1;
Continue;
end;
if h = 0 then Continue;
if (tmpDistY >= h) then
begin
TPARemove(ThePoints, i);
LTPA := LTPA - 1;
end;
end;
if Sort then SortTPAFrom(Arr, inttopoint(x, y));
Result := ThePoints;
end;



Array Removal:

{*******************************************************************************
procedure TPARemove(var Arr: TPointArray; Index: Integer);
By: lordsaturn
Description: Will remove an index from a TPointArray
*******************************************************************************}
procedure TPARemove(var Arr: TPointArray; Index: Integer);
begin
tSwap(Arr[Index], Arr[Length(Arr) - 1]);
SetLength(Arr, Length(Arr) - 1);
end;


{*******************************************************************************
function TPAMultiRemove(Arr: TPointArray; From, Last: integer; Sort: Boolean): TPointArray;
By: lordsaturn
Description: Will remove multiple indexes from a TPointArray. Will sort if true.
*******************************************************************************}
function TPAMultiRemove(Arr: TPointArray; From, Last: integer; Sort: Boolean): TPointArray;
var
i, c: integer;
begin
for i := From to Last do
TPARemove(Arr, i);
if Sort then SortTPAFrom(Arr, Arr[0]);
Result := Arr;
end;


{*******************************************************************************
function TIARemove(Arr: TIntegerArray; Index: integer): TIntegerArray;
By: lordsaturn
Description: Will remove an index from an integer array.
*******************************************************************************}
function TIARemove(Arr: TIntegerArray; Index: integer): TIntegerArray;
var
i, arLength: integer;
begin
arLength := Length(Arr) - 1;
for i := Index to arLength - 1 do
Arr[i] := Arr[i + 1];
SetArrayLength(Arr, arLength);
Result := Arr;
end;


{*******************************************************************************
function TIAMultiRemove(Arr: TIntegerArray; From, Last: integer): TIntegerArray;
By: lordsaturn
Description: Will remove multiple indexes from an integer array.
*******************************************************************************}
function TIAMultiRemove(Arr: TIntegerArray; From, Last: integer): TIntegerArray;
var
i: integer;
begin
for i := From to Last do
Arr := TIARemove(Arr, i);
Result := Arr;
end;
[/INDENT]

lordsaturn

2008-09-29 02:55:18

Skill:



WoodCutting.scar
[INDENT]

{*******************************************************************************
function IsEnt(fx, fy: integer): Boolean;
By: lordsaturn
Description: Returns true if an ent is near the given coords.
*******************************************************************************}
function IsEnt(fx, fy: integer): Boolean;
var
x, y, CTS: integer;
L: Extended;
c, c2: T2DIntArray;
begin
c := GetBitmapAreaColors(fx-30, fy-30, fx+30, fy+30);
Wait(100);
c2 := GetBitmapAreaColors(fx-30, fy-30, fx+30, fy+30);
CTS := GetColorToleranceSpeed;

ColorToleranceSpeed(2);
SetColorspeed2Modifiers(0.15, 0.5);
for x := 0 to 60 do
for y := 0 to 60 do
begin
if not SimilarColors(c[x][y], 5013108, 20) then
c[x][y] := 0;
if not SimilarColors(c2[x][y], 5013108, 20) then
c2[x][y] := 0;
end;
SetColorspeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(1);

for x := 0 to 60 do
for y := 0 to 60 do
if (not(SimilarColors(c[x][y], c2[x][y], 5))) and
((c[x][y] <> 0) or (c[x][y] <> 0)) then
Inc(L);
Result := (L/(1.0*61*61)*100) > 30;
ColorToleranceSpeed(CTS);
end;

{*******************************************************************************
function IsEntText: Boolean;
By: lordsaturn
Description: Returns true if an the uptext hints there is an ent.
*******************************************************************************}
function IsEntText: Boolean;
var
CTS: Integer;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.03, 0.75);
Result := CountColorTolerance(118478, 9, 10, 124, 23, 4) > 10;
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
end;
[/INDENT]

lordsaturn

2008-09-29 02:56:18

Reflection:



Interfaces.scar
[INDENT]

function GetQP: integer;
var
s: string;
begin
if not LoggedIn then Exit;
GameTab(3);
s := GetInterfaceText(274, 2);
Delete(s, 1, 14);
Result := StrToIntDef(s, -1);
end;
[/INDENT]

Sp0rky

2008-09-29 07:23:53

Wow, When i was teaching you 2 years ago I never dreamt of this. You made me proud ^_^

n3ss3s

2008-09-29 07:29:54

We need to have an epic discussion about HSL.

SetColorSpeed2Modifers.

a) Only has effect when using HSL, so, add an if()then.
b) These modifiers are the Hue and Saturation modifiers, that SCAR's SimilarColors will use (that color finding functions use). The tolerance we use while in the CTS 2 mode, or in other words, using HSL, is the L, Luminosity, Luminance, whatever you want to call it. Now, SimilarColors does

Hue * Luminosity and Sat * Luminosity, and compares those values of the other color input in SimilarColors. This way, we only need to use one variable to adjust tolerance, instead of doing 3x work comparing Hue and Saturation too.


So, when you have 0.2 and 0.2, the standard ones, as the modifiers, it detects colors within 2.0 and 2.0 Hue and Saturation difference, not 0.2 and 0.2.

bullzeye95

2008-09-29 07:38:21

I think that SRL needs to be seriously cleaned up, and one to two lined functions, like your CTS ones, shouldn't be added.

For
function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
var
i: integer;

begin
if Length(Colors) = 0 then Exit;
Result := True;
for i := 0 to Length(Colors) - 1 do
begin
FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
if Length(ResultTPA[i]) = 0 then
Result := False;
end;
end;
Try something like this instead:
function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
var
i, Hi: integer;

begin
if Length(Colors) = 0 then Exit;
Result := True;
Hi:= High(Colors);
for i := 0 to Hi do
begin
FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
if Length(ResultTPA[i]) = 0 then
begin
Result := False;
exit;
end;
end;
end;
(Same for the one after it)

I think MidPoint is already in wizzup's plugin.

lordsaturn

2008-09-29 08:16:53

From: n3ss3s
We need to have an epic discussion about HSL.

SetColorSpeed2Modifers.

a) Only has effect when using HSL, so, add an if()then.
b) These modifiers are the Hue and Saturation modifiers, that SCAR's SimilarColors will use (that color finding functions use). The tolerance we use while in the CTS 2 mode, or in other words, using HSL, is the L, Luminosity, Luminance, whatever you want to call it. Now, SimilarColors does

Hue * Luminosity and Sat * Luminosity, and compares those values of the other color input in SimilarColors. This way, we only need to use one variable to adjust tolerance, instead of doing 3x work comparing Hue and Saturation too.


So, when you have 0.2 and 0.2, the standard ones, as the modifiers, it detects colors within 2.0 and 2.0 Hue and Saturation difference, not 0.2 and 0.2.


I think i understand, so SimilarColors uses Luminosity and Sat instead of just Saturation?



From: bullzeye95
I think that SRL needs to be seriously cleaned up, and one to two lined functions, like your CTS ones, shouldn't be added.


You're absolutely right. I understand a lot of these functions have no chance of being added into SRL. I post them anyways for my personal value, and for everyone else to see.


For
function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
var
i: integer;

begin
if Length(Colors) = 0 then Exit;
Result := True;
for i := 0 to Length(Colors) - 1 do
begin
FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
if Length(ResultTPA[i]) = 0 then
Result := False;
end;
end;
Try something like this instead:
function FindColorsArrayTolerance(var ResultTPA: T2DPointArray; var Colors: TIntegerArray; xs, ys, xe, ye, Tol: integer): Boolean;
var
i, Hi: integer;

begin
if Length(Colors) = 0 then Exit;
Result := True;
Hi:= High(Colors);
for i := 0 to Hi do
begin
FindColorsTolerance(ResultTPA[i], Colors[i], xs, ys, xe, ye, Tol);
if Length(ResultTPA[i]) = 0 then
begin
Result := False;
exit;
end;
end;
end;
(Same for the one after it)

I think MidPoint is already in wizzup's plugin.


But if you exit the function, it won't find the colors for each value of the color array. BTW I improved these and reuploaded them.
And my midpoint function is for two points, wizzy's is for a TPA.


From: Sp0rky
Wow, When i was teaching you 2 years ago I never dreamt of this. You made me proud ^_^


Thanks, Sp0rk. I appreciate all of your help way back when :)

jakeyboy29

2008-09-29 08:49:16

nice, should help me a lot with my scripting.

mastaraymond

2008-09-29 08:53:29

Nice st00f :).

nielsie95

2008-09-29 09:44:23

From: n3ss3s
So, when you have 0.2 and 0.2, the standard ones, as the modifiers, it detects colors within 2.0 and 2.0 Hue and Saturation difference, not 0.2 and 0.2.


1 tolerance will look for 0.2 difference, 10 tolerance will look for 2.0 difference.

Laur€ns

2008-09-29 09:45:55

Very naice :p

lordsaturn

2008-09-29 11:41:40

From: nielsie95
1 tolerance will look for 0.2 difference, 10 tolerance will look for 2.0 difference.


Okay, I understand. So then what is the point of setting the ColorSpeed2Modifiers, if they are automatically calculated by the tolerance?

nielsie95

2008-09-29 13:01:43

From: lordsaturn
Okay, I understand. So then what is the point of setting the ColorSpeed2Modifiers, if they are automatically calculated by the tolerance?


I think that's what n3ss3s tried to explain. It's tolerance * modifier. So, actually, you have a tolerance for each part (H, S and L). The L tolerance is the tolerance you pass with FindColor. The tolerance for H and S is calculated through the modifiers.

So when you have modifiers (H: 0.1; S: 2.5) and do the following FindColor:

FindColorTolerance(x, y, clRed, 0, 0, 10, 10, 10)
(Search for a red color with tolerance 10)

Your L tolerance is now 10
Your H tolerance is now 0.1 * 10 = 1
Your S tolerance is now 2.5 * 10 = 25



clRed converted to HSL is (0, 100, 50). All matching colors have HSL values like this:

H: -10 to 10
S: 99 to 101
L: 25 to 75

bullzeye95

2008-09-29 17:17:59

From: lordsaturn

But if you exit the function, it won't find the colors for each value of the color array. BTW I improved these and reuploaded them.


Oh, I see. I wasn't really getting what that function was supposed to do.

About that midpoint, maybe it's in one of the many other plugins that I seem to have gathered over time…

lordsaturn

2008-09-30 23:14:49

From: nielsie95
I think that's what n3ss3s tried to explain. It's tolerance * modifier. So, actually, you have a tolerance for each part (H, S and L). The L tolerance is the tolerance you pass with FindColor. The tolerance for H and S is calculated through the modifiers.

So when you have modifiers (H: 0.1; S: 2.5) and do the following FindColor:

FindColorTolerance(x, y, clRed, 0, 0, 10, 10, 10)
(Search for a red color with tolerance 10)

Your L tolerance is now 10
Your H tolerance is now 0.1 * 10 = 1
Your S tolerance is now 2.5 * 10 = 25



clRed converted to HSL is (0, 100, 50). All matching colors have HSL values like this:

H: -10 to 10
S: 99 to 101
L: 25 to 75



Okay, I understand now, thanks for clearing that up.
But one more question..What role does SimilarColors have in the colorfinding procedures?


Edit: Update.

nielsie95

2008-10-03 03:16:54

SimilarColor checks if two colors match.

So, from my previous example:

clRed converted to HSL is (0, 100, 50). All matching colors have HSL values like this:

H: -10 to 10
S: 99 to 101
L: 25 to 75


If you do a FindColorsTolerance (cts = 2), all the colors with the above specifications will be returned.

Nava2

2008-10-09 22:24:14

Where is the StrToStrArray function?

lordsaturn

2008-10-09 22:37:39

From: Nava2
Where is the StrToStrArray function?


misc/arrayLoader.scar

i'll probably make an alternative soon.

lordsaturn

2008-10-30 18:36:19

From: NaumanAkhlaQ
CheckQuest is broken. You have function in there which aren't in srl?


It's not broken, It just uses my functions 'TrimString' and 'FindTextArrayTPAEx'.

R0b0t1

2009-01-31 23:48:39

Actually, one to two lined functions (well, more like macros) are common in most standards. Just because they're small doesn't mean they shouldn'd be included, as a standard is just… for… often used stuff…?