PDA

View Full Version : Small Tut. (ColorToleranceSpeed)



Wizzup?
04-15-2007, 04:26 PM
These are the functions we will discuss.


procedure ColorToleranceSpeed(x: Integer);
Sets the speed of tolerance comparisons. ColorToleranceSpeed(1) is a little slower then 0 but more accurate. ColorToleranceSpeed(0) is faster but not as accurate as 1. ColorToleranceSpeed(2) uses Hue, Saturation and Lightness to determine color similarity.

procedure SetColorspeed2Modifiers(huemodifier, saturationmodifier: Extended);
These work when ColorToleranceSpeed(2) has been set. Normally Tolerance parameter in this mode applies to Luminance directly. For an example, SimilarColors(c1, c2, 10) would work if both colors differ by 10 max luminance. After calling SetColorspeed2Modifiers(0.2, 2) it would mean that SimilarColors(c1, c2, 10) would check for Hue in range of 2 and Saturation in range of 20. Default huemodifier and saturationmodifier is 0.2.



Simple ColorToleranceSpeed text:

program New;

Function SimC: integer;

Var I : integer;

Begin
For I := 0 to 255 do
if similarcolors(15714472, 14585952, I) then break;
if i <> 255 then result := i;
End;

Var
I : Integer;
begin
SetColorspeed2Modifiers(0.2, 0.2)
For I := 0 to 2 Do
Begin
writeln('with colortolerancespeed '+inttostr(I));
colortolerancespeed(I);
writeln('tol : ' + inttostr(SimC));
End;
end.


with colortolerancespeed 0
tol : 72
with colortolerancespeed 1
tol : 93
with colortolerancespeed 2
tol : 18

SCAR's Normal ColorToleranceSpeed is 1.

As you can see, different tolerances. :)
In this case, SetColorspeed2Modifiers(0.2, 0.2) is default, so you don't need to call it:


Default huemodifier and saturationmodifier is 0.2.


But... You can adept those! (wow, like you didn't expect that)

program New;

Function SimC: integer;

Var I : integer;

Begin
For I := 0 to 255 do
if similarcolors(15714472, 14585952, I) then break;
if i <> 255 then result := i;
End;

Var
I : Integer;
begin
SetColorspeed2Modifiers(0.1, 0.1)
For I := 0 to 2 Do
Begin
writeln('with colortolerancespeed '+inttostr(I));
colortolerancespeed(I);
writeln('tol : ' + inttostr(SimC));
End;
end.


tol : 72
with colortolerancespeed 1
tol : 93
with colortolerancespeed 2
tol : 34

Use ColorToleranceSpeed like this:

Function FindFishingSpot(Var x, y: Integer): Boolean;

Var
I, ArrC, MinX, MinY, MaxX, MaxY, FishColor: Integer;
FPt: TPointArray;

Begin
if x = $0 then x := $106;
if y = $0 then y := $AA;
ColorToleranceSpeed(2);
If FindColorSpiralTolerance(x, y, 15181944, 5, 5, 515, 336, 20) Then
Begin
FishColor := GetColor(x, y);
FindColorsSpiralTolerance(x, y, FPt, FishColor, x - 20, y - 20, x + 20, y + 20, 40)
ArrC := GetArrayLength(FPt);
MinX := 1 Shl 10;
MinY := 1 Shl 10;
For I := 0 To ArrC - 1 Do
Begin
MaxX := Max(MaxX, FPt[I].X);
MinX := Min(MinX, FPt[I].X);
MaxY := Max(MaxY, FPt[I].Y);
MinY := Min(MinY, FPt[I].Y);
End;
x := (MaxX + MinX) Shr 1;
y := (MaxY + MinY) Shr 1;
Result := True;
ColorToleranceSpeed(1);
Exit;
End Else WriteLn('Color Not Found.');
ColorToleranceSpeed(1);
End;


~ Wizzup?

ShawnjohnSJ
04-16-2007, 04:14 AM
Nice tutorial! :]
OH yes yes!

Wizzup?
04-16-2007, 09:08 AM
Nice tutorial! :]
OH yes yes!

Glad you like it, these functions are very usefull, it's really an nice addition to colorfinding.

Smartzkid
04-19-2007, 08:34 PM
Wow, never knew about this

Thanks!

lordsaturn
04-19-2007, 08:54 PM
Thanks! This is just what i needed for making my new script! Great Job Wizzup?!