Results 1 to 21 of 21

Thread: Easy(To use) AutoColor Funtion!

  1. #1
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Easy(To use) AutoColor Funtion!

    For all people who doesnt know how to autocolor, i made a function easy to use:

    SCAR Code:
    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 .


  2. #2
    Join Date
    Mar 2006
    Posts
    3,051
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    It would be cool if you used the original color RGB values to compare against the found color as well.


  3. #3
    Join Date
    Mar 2008
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    How do you find the best tolerance to put it at?

  4. #4
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by tarajunky View Post
    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

    Quote Originally Posted by sirlaughsalot View Post
    How do you find the best tolerance to put it at?
    20 - 60 depends on the color.


  5. #5
    Join Date
    Mar 2008
    Posts
    1,492
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Total noob question, but how would you use this in a script?

  6. #6
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by sirlaughsalot View Post
    Total noob question, but how would you use this in a script?
    SCAR Code:
    RadialWalk(AutoColorColor(156112, 20), bla, bla...);


  7. #7
    Join Date
    Mar 2006
    Posts
    3,051
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    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.


  8. #8
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    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.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  9. #9
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by R0b0t1 View Post
    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?

    Quote Originally Posted by tarajunky View Post
    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:
    SCAR 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?


  10. #10
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

  11. #11
    Join Date
    Mar 2006
    Posts
    3,051
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    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).

    SCAR Code:
    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;


  12. #12
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by tarajunky View Post
    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).

    SCAR Code:
    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.
    Quote Originally Posted by Da 0wner View Post
    Typo: You said designed in the function description. Shouldn't it be designated?
    yes


  13. #13
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    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
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  14. #14
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    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.


  15. #15
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Cazax, remove the useless begin-ends...

  16. #16
    Join Date
    Jan 2008
    Location
    California, US
    Posts
    2,765
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    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

  17. #17
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Da 0wner View Post
    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
    Nah, n3ss3s capitalize them, so i copied him

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


  18. #18
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    765
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    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.


    ^LOL^

  19. #19
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by kor View Post
    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.
    SCAR Code:
    Var
      WalkColor : TColor; // Or whatever
    ................
    WalkColor := MMGetColor(2263121, 30);
    RadialWalk(WalkColor, ....);
    This is a pretty good function for the walking .


  20. #20
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    765
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by Cazax View Post
    SCAR Code:
    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


    ^LOL^

  21. #21
    Join Date
    Jul 2007
    Posts
    140
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Where should i insert color? Trying to learn howto script

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. funtion DownloadImage
    By Da 0wner in forum Research & Development Lounge
    Replies: 23
    Last Post: 05-05-2009, 07:55 PM
  2. AutoColor
    By Bobzilla69 in forum OSR Help
    Replies: 4
    Last Post: 07-15-2008, 07:21 AM
  3. How do i use AutoColor?
    By Claymore in forum OSR Help
    Replies: 9
    Last Post: 07-07-2008, 11:21 AM
  4. funtion TypeHuman(Test:String;MilisecondPerLett:Integer):S tring;
    By Daniel in forum Research & Development Lounge
    Replies: 22
    Last Post: 01-04-2008, 04:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •