Results 1 to 6 of 6

Thread: GetUniqueSymbolColor, Symbol.scar

  1. #1
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default GetUniqueSymbolColor, Symbol.scar

    I thought this might be useful, pretty much it finds a unique color on or around (like 3 pixels away) a given symbol. It first autocolors the symbol, then searches for the black around the symbol creating a Tbox, then gets all the colors in the Tbox and finds a unique color inside the box.

    I found it works really well with Tree Symbols, and on symbols like Smithing that do not have one unique color, it gets a color right near it. Anyways, here's code (for some reasons its negating the spaces between Functions):

    SCAR Code:
    {*******************************************************************************
    Function GetSymbolArea(Color: Integer; Hue, Sat: Extended; Tol: Integer): TPointArray;
    By: Blumblebee
    Description: Gathers Points of a particular color into a TPA Dependant on the Color,
                 Hue, Sat, and Tol provided.
    *******************************************************************************}


    Function GetSymbolArea(Color: Integer; Hue, Sat: Extended; Tol: Integer): TPointArray;
    var TPA: TPointArray; ATPA: T2DPointArray; P: TPoint; l, i: integer;
    begin
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(Hue, Sat);
      FindColorsSpiralTolerance(MMcx, MMcy, TPA, Color, MMx1, MMy1, MMx2, MMy2, Tol);
      ColorToleranceSpeed(1);
      SetColorSpeed2Modifiers(0.2, 0.2);
      if Length(TPA) <= 0 then Exit;
      ATPA := SplitTPAEx(TPA, 5, 5);
      for i := 0 to High(ATPA) do
      begin
        P := MiddleTPA(ATPA[i]);
        if rs_OnMiniMap(P.x,P.y) then
        begin
          l := getarraylength(Result);
          SetArrayLength(Result, l+1);
          Result[l] := P;
        end;
      end;
    end;

    {*******************************************************************************
    Function CreateSymbolBox(TPA: TPointArray; TP: TPoint): TBox;
    By: Blumblebee
    Description: Creates a TBox around a cluster in a TPA. The TBox is created in
                 reference to the Black outside of the Symbol.
    *******************************************************************************}


    Function CreateSymbolBox(TPA: TPointArray; TP: TPoint): TBox;
    var nTPA, oTPA: TPointArray;
    begin
      oTPA := TPA;
      sortTPAFrom(oTPA, Point(TP.x, TP.y));
      FindColorsTolerance(nTPA, 65536, oTPA[0].x-7, oTPA[0].y-7, oTPA[0].x+7, oTPA[0].y+7, 10);
      if Length(nTPA) > 0 then
        Result := GetTPABounds(nTPA);
    end;

    {*******************************************************************************
    Function FindUniqueColors(Col: Integer; rTPA: TPointArray; Area: TPoint): Integer;
    By: Blumblebee
    Description: Gathers all Colors inside the "symbol box", and sorts for the most
                 unique color that is closest to the given color.
    *******************************************************************************}


    Function FindUniqueColors(Col: Integer; rTPA: TPointArray; Area: TPoint): Integer;
    var SymBox: TBox; TPA: TPointArray; List1, List2, List3 : TIntegerArray; i, ii, Tol, L: integer;
    begin
      SymBox := CreateSymbolBox(rTPA, Area);
      FindColorsTolerance(TPA, 0, SymBox.x1, SymBox.y1, SymBox.x2, SymBox.y2, 225);
      List1 := GetColors(TPA);
      List2 := List1;
      ClearSameIntegers(List1);
      for i := 0 to High(List2) do
      begin
        for ii := 0 to High(List1) do
        begin
          if List1[ii] = List2[i] then
          begin
            L := getarraylength(List3);
            SetArrayLength(List3, L+1);
            List3[L] := List1[ii];
          end;
        end;
      end;
      Tol := 5;
      while Result = 0 do
      begin
        for i := 0 to High(List3) do
        begin
          if SimilarColors(List3[i], Col, Tol) then
          begin
            Result := List3[i];
            WriteLn('Unique Symbol Color = '+IntToStr(Result));
            Exit;
          end;
        end;
        IncEx(Tol, 1);
      end;
    end;

    {*******************************************************************************
    GetUniqueSymbolColor(x, y: Integer; Color: Integer; Hue, Sat: Extended; Tol: Integer): Integer;
    By: Blumblebee
    Description: Finds the most unique symbol color with the information given.
    *******************************************************************************}


    Function GetUniqueSymbolColor(x, y: Integer; Color: Integer; Hue, Sat: Extended; Tol: Integer): Integer;
    begin
      Result := FindUniqueColors(Color, GetSymbolArea(Color, Hue, Sat, Tol), Point(x, y));
    end;

    an example of using this would be as so:

    SCAR Code:
    var r, x, y: Integer;

    begin
      SetUpSRL;
      r := GetUniqueSymbolColor(MMcx, MMy2, 229638, 0.17, 0.45, 15);
      FindColor(x, y, r, MMx1, MMy1, MMx2, MMy2);
      MMouse(x, y, 3, 3);
    end.

    debug reads:

    Successfully compiled (3571 ms)
    SRL Compiled in 16 msec
    Unique Symbol Color = 494860
    This works for the Tree Symbol in edgeville (as viewed from the bank).

    There is an Area parameter (x, y) which allows the user to choose where the script searches from, so that if there is more than one of the same symbol on the MM, it will find the the closest to the point specified.

    @Wizzup: I tried to impliment the sorting idea you showed me, but I found I recieved identical results to this one, so I left be.

  2. #2
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Cool to see you released it
    Only thing that bugs me is that you have to insert Hue and Sat... :/
    EDIT: I found a problem, if the color is the same as the colors around the minimap (brown-ish) then it will click outside the minimap and the script wouldn't work..
    EDIT2: I tried finding the "log" symbol in GE, it found a color but the color was the same as the floor in the GE resulting is scar clicking the ground
    EDIT3: If there is symbols with the same colors then it will sometime click the wrong symbol.
    Last edited by Zyt3x; 11-23-2009 at 01:56 PM.

  3. #3
    Join Date
    Mar 2007
    Location
    <3
    Posts
    2,683
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You should add function info on top of all your functions.

  4. #4
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Zyt3x View Post
    Cool to see you released it
    Only thing that bugs me is that you have to insert Hue and Sat... :/
    EDIT: I found a problem, if the color is the same as the colors around the minimap (brown-ish) then it will click outside the minimap and the script wouldn't work..
    EDIT2: I tried finding the "log" symbol in GE, it found a color but the color was the same as the floor in the GE resulting is scar clicking the ground
    EDIT3: If there is symbols with the same colors then it will sometime click the wrong symbol.
    Ok, well the MM problem can be fixed by how the player chooses to click I suppose. I may as well write a clicking function too, but I figured that would be overkill. You would simplly have to do something like
    SCAR Code:
    FindColorSkipBox()
    or just make a more specific area in clicking, I'm not sure how else I could make it more accurate in that respect. an RS_OnMiniMap() check might also be useful for the minimap border problem I'll look into.

    Quote Originally Posted by N1ke! View Post
    You should add function info on top of all your functions.
    yeah I'll get on that sorry. edit: Done, I'm really bad at explaining stuff though haha

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

    Default

    I don't really see what the point of this is?
    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

  6. #6
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    I don't really see what the point of this is?
    I don't find FindSymbol very accurate, and so when I walk via a symbol I prefer using a TPA. This is pretty much an autocolor for every Symbol allowing you to use it for walking, or a reference color to see if your in a certain area or not.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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