PDA

View Full Version : Easy(To use) AutoColor Funtion!



Cazax
05-02-2008, 02:29 AM
For all people who doesnt know how to autocolor, i made a function easy to use:


Function MMGetColor(Color : TColor; Tol : Integer): Integer;
Var
TPA : TPointArray;
Tols,Cols : TIntegerArray;
I,II,Dist,R,G,B,R1,G1,B1,MinTol : Integer;
Begin
ColorToRGB(Color, R, G, B);
FindColorsSpiralTolerance(MMCX, MMCY, TPA, Color, MMX1, MMY1, MMX2, MMY2, Tol);
If Length(TPA) < 1 Then
Begin
Writeln('No Colors Found!');
Result := 0;
Exit;
End;
Cols := GetColors(TPA);
SetArrayLength(Tols, Length(Cols));
For I := 0 To High(Cols) Do
Begin
For II := 0 To Tol Do
Begin
If SimilarColors(Color, Cols[I], II) Then
Begin
Tols[I] := Tols[I] + II;
Break;
End;
End;
ColorToRGB(Cols[I], R1, G1, B1);
Dist := ((Max(r, r1) - Min(r, r1)) + (Max(g, g1) - Min(g, g1)) + (Max(b, b1) - Min(b, b1))) Div 3;
Tols[I] := Tols[I] + Dist;
End;
For I := 0 To High(Tols) Do
Begin
If (Tols[I] < MinTol) Then
Begin
MinTol := Tols[I];
Result := Cols[I];
End;
End;
If Result <> 0 Then Exit
Else
Begin
Result := 0;
Writeln('Failed while autocoloring!');
End;
End;
Color: Color to search.
Tol:The max tolerance to search the color.

It basically finds all the color that are similar to Color. Then it compare if the colors are similar with the TPA, then it gets the color and thats all :) .

tarajunky
05-02-2008, 02:36 AM
It would be cool if you used the original color RGB values to compare against the found color as well.

sirlaughsalot
05-02-2008, 03:37 AM
How do you find the best tolerance to put it at?

Cazax
05-02-2008, 03:34 PM
It would be cool if you used the original color RGB values to compare against the found color as well.
You really own tara :) im going to add that
EDIT: Added :)


How do you find the best tolerance to put it at?
20 - 60 depends on the color.

sirlaughsalot
05-03-2008, 03:26 AM
Total noob question, but how would you use this in a script?

Cazax
05-03-2008, 04:03 AM
Total noob question, but how would you use this in a script?

RadialWalk(AutoColorColor(156112, 20), bla, bla...);

tarajunky
05-03-2008, 03:51 PM
It looks like you're only finding the most similar color based on tolerance alone. If that found color isn't within the RGB range, the function has no way to go back and find more colors.

Other than that it looks good, but you might need different CTol variables for the Color Tolerance and the Range Tolerance. Does it work?

A different way to do the same thing would be something like this.

Do one search at max tolerance to grab ALL the possible colors.
FindColorsSpiralTolerance(Array, blah, blah, MaxTol);
Some sort of ShrinkArray to eliminate duplicate colors.

Then assign every color in the array a value = to the color tolerance and the RGB tolerance.

for i:= 0 to High(Array) do
begin
for j:= 0 to MaxTol do
begin
if SimilarColors(Color,Array[i],j) then
begin
Array2[i]:=Array2[i]+j;
break;
end;
end;
ColorToRGB(Color,r,g,b);
ColorToRGB(Array[i],r1,g1,b1);
*Some kind of distance calculation...*
dist:=SQRT(((R-R1)*(R-R1))+((G-G1)*(G-G1))+((B-B1)+(B-B1)));
Array2[i]:=Array2[i]+dist;
end;
for i:= 0 to High(Array2) do
begin
if Array2[i]<Min then result:=Array[i];
end;

The code probably won't work as it is now, but that would give you the most similar color to what you're searching for.

Remember that the color searches are the slowest part of the function, so doing one search with more calculations will be faster than many searches with fewer calculation.

R0b0t1
05-06-2008, 11:34 PM
But why do you insist on comparing it as RGB? Saying "How to I convert this color to RGB?" is like saying "How do I turn this ice into water?".


Sure, the subtle difference (as between water and ice, although the same substance) could be what you need... But comparing them another way might be faster/better.

Cazax
05-08-2008, 12:08 AM
But why do you insist on comparing it as RGB? Saying "How to I convert this color to RGB?" is like saying "How do I turn this ice into water?".


Sure, the subtle difference (as between water and ice, although the same substance) could be what you need... But comparing them another way might be faster/better.
R0b0t1, Are you talking to tara?


It looks like you're only finding the most similar color based on tolerance alone. If that found color isn't within the RGB range, the function has no way to go back and find more colors.

Other than that it looks good, but you might need different CTol variables for the Color Tolerance and the Range Tolerance. Does it work?

A different way to do the same thing would be something like this.

Do one search at max tolerance to grab ALL the possible colors.
FindColorsSpiralTolerance(Array, blah, blah, MaxTol);
Some sort of ShrinkArray to eliminate duplicate colors.

Then assign every color in the array a value = to the color tolerance and the RGB tolerance.

for i:= 0 to High(Array) do
begin
for j:= 0 to MaxTol do
begin
if SimilarColors(Color,Array[i],j) then
begin
Array2[i]:=Array2[i]+j;
break;
end;
end;
ColorToRGB(Color,r,g,b);
ColorToRGB(Array[i],r1,g1,b1);
*Some kind of distance calculation...*
dist:=SQRT(((R-R1)*(R-R1))+((G-G1)*(G-G1))+((B-B1)+(B-B1)));
Array2[i]:=Array2[i]+dist;
end;
for i:= 0 to High(Array2) do
begin
if Array2[i]<Min then result:=Array[i];
end;

The code probably won't work as it is now, but that would give you the most similar color to what you're searching for.

Remember that the color searches are the slowest part of the function, so doing one search with more calculations will be faster than many searches with fewer calculation.
FINALLY i understood what were you saying, thank you so much tara :) now, look at the code:
Function MMGetColor(Color : TColor; Tol : Integer): Integer;
Var
TPA : TPointArray;
Tols,Cols : TIntegerArray;
I,II,Dist,R,G,B,R1,G1,B1 : Integer;
Begin
ColorToRGB(Color, R, G, B);
FindColorsSpiralTolerance(MMCX, MMCY, TPA, Color, MMX1, MMY1, MMX2, MMY2, Tol);
If Length(TPA) < 1 Then
Begin
Writeln('No Colors Found!');
Result := 0;
Exit;
End;
Cols := GetColors(TPA);
SetArrayLength(Tols, Length(Cols));
For I := 0 To High(Cols) Do
Begin
For II := 0 To Tol Do
Begin
If SimilarColors(Color, Cols[I], II) Then
Begin
Tols[I] := Tols[I] + II;
Break;
End;
End;
ColorToRGB(Cols[I], R1, G1, B1);
Dist := ((Max(r, r1) - Min(r, r1)) + (Max(g, g1) - Min(g, g1)) + (Max(b, b1) - Min(b, b1))) Div 3;
Tols[I] := Tols[I] + Dist;
End;
For I := 0 To High(Tols) Do
Begin
If (Tols[I] < Tol) Then
Result := Cols[I];
Exit;
End;
Result := 0;
Writeln('Failed while autocoloring!');
End;
Anything more to add?

Da 0wner
05-08-2008, 01:50 AM
Typo: You said designed in the function description. Shouldn't it be designated?

tarajunky
05-08-2008, 02:42 AM
That looks really good, but I think there's one error. You don't want to exit out of the bottom loop. You want it to go through all the colors you found, and pick out the lowest one. You can either re-use one of your integer variables, or define a new one. I'm assuming you define a new one called (MinTol).


MinTol:=Tols[0]; // You just pick the first color to start with as reference.
Result:=Cols[0]; // If it happens to be the best color, this will return it.
For I := 0 To High(Tols) Do //Scans through all the rest of the colors
Begin
If (Tols[i] < MinTol) Then// If lower that the lowest so far
begin
MinTol:=Tols[i];// Update minimum tolerance
Result := Cols[i];// Update result. No exit so it scans all colors.
end;
End;

Cazax
05-08-2008, 09:42 PM
That looks really good, but I think there's one error. You don't want to exit out of the bottom loop. You want it to go through all the colors you found, and pick out the lowest one. You can either re-use one of your integer variables, or define a new one. I'm assuming you define a new one called (MinTol).


MinTol:=Tols[0]; // You just pick the first color to start with as reference.
Result:=Cols[0]; // If it happens to be the best color, this will return it.
For I := 0 To High(Tols) Do //Scans through all the rest of the colors
Begin
If (Tols[i] < MinTol) Then// If lower that the lowest so far
begin
MinTol:=Tols[i];// Update minimum tolerance
Result := Cols[i];// Update result. No exit so it scans all colors.
end;
End;

Ok thanks added. Im thinking on making one for the main screen. That would be so useful.

Typo: You said designed in the function description. Shouldn't it be designated?
yes :)

Nava2
05-10-2008, 02:50 PM
So, you use this to:

1. You place the color close;
2. It finds the color or SIMILAR colors;
3. Returns the closest color AKA the best color to search for.

Correct?

Nava2

Cazax
05-10-2008, 03:53 PM
So, you use this to:

1. You place the color close;
2. It finds the color or SIMILAR colors;
3. Returns the closest color AKA the best color to search for.

Correct?

Nava2
It finds the most similar color comparing it with the color you input.

n3ss3s
05-10-2008, 05:03 PM
Cazax, remove the useless begin-ends...

Da 0wner
05-19-2008, 11:02 PM
And don't capitalize the bolded words, because I think that is part of the standards. Correct me if i'm wrong.

p.s It is wierd to see n3ss3s as a developer :p

Cazax
05-19-2008, 11:09 PM
And don't capitalize the bolded words, because I think that is part of the standards. Correct me if i'm wrong.

p.s It is wierd to see n3ss3s as a developer :p
Nah, n3ss3s capitalize them, so i copied him :p

@n3ss3s: Some begins-ends are important becouse if you test this:
program New;
Begin
If (Rbool = True) Then
Writeln('RBool = True');
Writeln('W00t');
End.
and what do you get?

w00t:)

kor
05-20-2008, 12:56 PM
hmm, i really need to use an autocolor function, and this looks good. i have never used one before so i could use a little help. my radial walk looks like this atm ''RadialWalk(2263121,350,330,72,99,99);'' and if i want to use this autocolor function, then what will it look like? i just want to make sure i do it right ;) thanks.

Cazax
05-20-2008, 09:15 PM
hmm, i really need to use an autocolor function, and this looks good. i have never used one before so i could use a little help. my radial walk looks like this atm ''RadialWalk(2263121,350,330,72,99,99);'' and if i want to use this autocolor function, then what will it look like? i just want to make sure i do it right ;) thanks.

Var
WalkColor : TColor; // Or whatever
................
WalkColor := MMGetColor(2263121, 30);
RadialWalk(WalkColor, ....);
This is a pretty good function for the walking :) .

kor
05-20-2008, 09:23 PM
Var
WalkColor : TColor; // Or whatever
................
WalkColor := MMGetColor(2263121, 30);
RadialWalk(WalkColor, ....);
This is a pretty good function for the walking :) .
thanks man! i will try it ;) you're awesome tbh.

EDIT: okey i tried it, but it didnt work out for me :/ i started lagging just before it was going to start autocoloring so it failed. ill have to figure something out

gl3nni
10-08-2008, 05:20 AM
Where should i insert color? Trying to learn howto script