SRL Archive - SRL Archives

Muchos Bullcrap


n3ss3s

2008-09-29 12:44:01

{*******************************************************************************
Procedure AdjustAccordingly(Color1, Color2: Integer);
By: n3ss3s
Description: Adjusts your CTS 2 mods (if the mode is 2) to fit the difference
between the two colors.
*******************************************************************************}

Procedure AdjustAccordingly(Color1, Color2, LumTol: Integer);

Var
HSL: Array of Array [0..2] of Extended;
Begin
If GetColorToleranceSpeed <> 2 Then
srl_Warn('AdjustAccordingly', 'CTS <> 2', 0)
Else
Begin
SetArrayLength(HSL, 3);
ColorToHSL(Color1, HSL[0][0], HSL[0][1], HSL[0][2]);
ColorToHSL(Color2, HSL[1][0], HSL[1][1], HSL[1][2]);
HSL[2][0] := Abs(HSL[0][0] - HSL[1][0]);
HSL[2][1] := Abs(HSL[0][1] - HSL[1][1]);
HSL[2][2] := Abs(HSL[0][2] - HSL[1][2]);
SetColorSpeed2Modifiers((HSL[2][0] + 0.0001) / LumTol, (HSL[2][1] + 0.0001 / LumTol);
End;
End;





I'll make some more if I feel like that.



Rock finder…


Function FindRocks(Color, Tol: Integer; tol_H, tol_S: Extended): TPointArray;


Var
TPA: TPointArray;
L, C, I: Integer;
B: TBox;
TPAA: T2DPointArray;
Begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(tol_H, tol_S);
FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2, MSY2, tol);
SetColorSpeed2Modifiers(0.2, 0.2);
TPAA := TPAToATPAEx(TPA, 30, 30);
L := High(TPAA);
SetArrayLength(Result, L + 1);
For I := 0 To L Do
If Length(TPAA[i]) < 65 Then
If Length(TPAA[i]) > 10 Then
Begin
B := GetTPABounds(TPAA[i]);
Try
If (Length(TPAA[i]) + 0.001) / ((B.x2 - B.x1) * (B.y2 - B.y1)) < 0.5 Then
Begin
Result[c] := Point((B.x2 + B.x1) shr 1, (B.y2 + B.y1) shr 1);
C := C + 1;
End;
Except End;
End;
SetArrayLength(Result, C);
ColorToleranceSpeed(1);
End;



Tree finder

Function TreePoints: T2DPointArray;


Var
S, I: Integer;
TPA, Other: TPointArray;
TPAA: T2DPointArray;
B: TBox;
Begin
S := GetSystemTime;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.15, 4.0);
FindColorsTolerance(TPA, 5079157, MSX1, MSY1, MSX2, MSY2, 20);
TPAA := SplitTPA(TPA, 3);
SortATPASize(TPAA, True);
For I := 0 To High(TPAA) Do
If GetArrayLength(TPAA[i]) < 25 Then
Begin
SetArrayLength(TPAA, i);
Break;
End;
SetColorSpeed2Modifiers(0.15, 4.0);
For I := 0 To High(TPAA) Do
Begin
B := GetTPABounds(TPAA[i]);
TPA := TPAA[i];
FindColorsTolerance(Other, 198920, B.x1, B.y1, B.x2, B.y2, 20);
TPAA[i] := CombineTPA(Other, TPA);
End;
Result := TPAA;
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(1);
Writeln('Took: ' + IntToStr(GetSystemTime - S));
End;


EvilChicken!

2008-09-29 16:31:27

Hmm, I think I like this mucho.
You just need to tell me whether this would work: in an array of similar colors, would it be possible to use the lowest color of those in the array as color1, and highest color as color2 and a function to find the best tolerance for use with those two colors?

I'm thinking about using the above mentioned method for smartcolors if I'm right and it could work ..

n3ss3s

2008-09-30 11:24:07

Well you can average the color from the array of stored colors and use that…

mastaraymond

2008-09-30 12:12:07

Find the lowest&highest H, Lowest & Highest S, Lowest & Highest L. Then You do (Low + High) / 2. Then you make a new color with all those middle points with a new tol, you can caluclate ^_^.

n3ss3s

2008-09-30 12:29:55



Function AverageColor(Colors: TIntegerArray): Integer;

Var
H, S, L, H1, S1, L1: Extended;
I: Integer;
Begin
For I := 0 To High(Colors) Do
Begin
ColorToHSL(Colors[i], H1, S1, L1);
H := H + H1;
S := S + S1;
L := L + L1;
End;
H := H / (i + 1);
S := S / (i + 1);
L := L / (i + 1);
End;

Sneaky little trick I did there to avoid doing a new High() ;)

BazzBarrett

2008-09-30 14:08:25

i like alot =) im a real big TPA fan now XD mind if i take this function apart and use it in my own ill credit u ;)

n3ss3s

2008-10-01 08:48:52

Sure

Narcle

2008-10-05 14:19:03

From: n3ss3s


Function AverageColor(Colors: TIntegerArray): Integer;

Var
H, S, L, H1, S1, L1: Extended;
I: Integer;
Begin
For I := 0 To High(Colors) Do
Begin
ColorToHSL(Colors[i], H1, S1, L1);
H := H + H1;
S := S + S1;
L := L + L1;
End;
H := H / (i + 1);
S := S / (i + 1);
L := L / (i + 1);
End;

Sneaky little trick I did there to avoid doing a new High() ;)


Haha, 'I' stays at High(Colors) after its called?

nielsie95

2008-10-05 14:23:14

High(Colors) + 1.

n3ss3s

2008-10-05 14:52:39


I sense that you are running on Windows Vista?

n3ss3s

2008-10-28 03:17:55

Omg Update!

Took: 188


Oops, the tree finder apparently sucks in speed.