SRL Archive - SRL Archives

Color.SCAR: Function BestTolerance(Colors: TIntegerArray): Integer;


marpis

2009-12-25 12:53:34

I don't know if this works how I think it works, but it should find the minimum tolerance with which all colors in the array "Colors: TIntegerArray" are found. So if you input clGreen, clRed, and clBlue it will result a very high tolerance, but if you input (clBlue - 1), (clBlue + 1) it will result a fairly small tolerance.

Please people, test it and tell me how you think it could be used! I don't commit it before it gets approved :rolleyes:


Function BestTolerance(Colors: TIntegerArray): Integer;
Var
I, II, Tol, H: Integer;
Begin
Result := -1;

H := High(Colors);
For I := 0 To H Do
For II := 0 To H Do
Begin
If (I = II) Then
Continue;

For Tol := 0 To 300 Do
If SimilarColors(Colors[I], Colors[II], Tol) Then
If (Tol > Result) Then
Begin
Result := Tol;
Break;
End;
End;
End;

JPHamlett

2009-12-25 13:21:57

looks nice i like it

Sex

2009-12-25 14:00:37

From: J_Pizzle
looks nice i like it

Have you tested it?

Cazax

2009-12-25 14:21:59

Function BestTolerance(Cols : TIntegerArray): Integer;
Var
H, I, J : Integer;
Begin
Result := -1;
H := High(Cols);
For I := 0 To H Do
For J := 0 To H Do
While Not SimilarColors(Cols[I], Cols[J], Result) Do
Inc(Result);
End;
Shortened.

marpis

2009-12-25 14:26:36

From: Cazax

Shortened.


Function BestTolerance(Cols : TIntegerArray): Integer;
Var
H, I, J : Integer;
Begin
Result := -1;
H := High(Cols);
For I := 0 To H Do
For J := 0 To H Do
If (I <> J) Then
While Not SimilarColors(Cols[I], Cols[J], Result) Do
Inc(Result);
End;

Lol, how come I didn't come up with that! :p
Thanks!

Wizzup?

2009-12-25 14:38:54

See a faster one here: http://freddy1990.com/forums/index.php?topic=3635.0 (For cts 0..2)

marpis

2009-12-25 14:58:06

From: Wizzup?
See a faster one here: http://freddy1990.com/forums/index.php?topic=3635.0 (For cts 0..2)


You mean a faster SimilarColors?
My BestTolerance compares a whole array of integers, not only 2 values.

Wizzup?

2009-12-25 15:32:44

From: marpis
You mean a faster SimilarColors?
My BestTolerance compares a whole array of integers, not only 2 values.


Didn't notice. My bad. The algorithms there still apply though.

Nava2

2009-12-25 20:56:30

This is in SRL.. :p

Check out color.scar ;)

marpis

2009-12-26 10:46:03

GetColorArrayInfo? This doesn't look like finding the minimum tolerance with which all the colors are found.. I have no idea what this does actually.

// Get Tolerances for each ColorSpeedTolerance, 3 is unknown so is skipped.
for i := 0 to 2 do
Tolerances[0] := Max(Tolerances[0], iAbs(Round(Result[0][i][1] - Result[0][i][0])));

Tolerances[1] := Ceil(sqrt(sqr(Result[0][0][0] - Result[0][0][1]) + sqr(Result[0][1][0] - Result[0][1][1])
+ sqr(Result[0][2][0] - Result[0][2][1])));

Tolerances[2] := Ceil(abs(Result[1][2][0] - Result[1][2][1]));
for i := 0 to 1 do
try Speed2Mods[i] := (abs(Result[1][i][0] - Result[0][i][1]) / Tolerances[2]); except Speed2Mods[i] := 0.0; end;


Sir R. M8gic1an

2009-12-26 14:07:48

rather than the if….

ClearSameIntegers(TIA) ?

~RM