Results 1 to 13 of 13

Thread: Colors and distance

  1. #1
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default Colors and distance

    This is a bit hard to explain but I'll give it my best shot. Let's say I wanted to find an object that has, atleast, 2 separate colors on it, and I was to find this object based on how close together those colors were? I imagine it has something to do with finding a TPA of both of those colors and merging them, but what about the distance?

    Here's an example, more or less:


    Getting the TPA of the brown, no problem. Same with the black. But as you can see those colors eventually change to the other there at the tree trunk. So... How would I find the distance, from the closest point of brown to the closest point of black? Would there be a way of telling if those two TPA's come within X amount of distance from one another? And if they're very close to each other, how would I get a point or TPA of where they become the closest?

    If someone has an example of how this might be done that'd be wonderful, as I'm the kind of person who learns best from looking at given samples. Thanks in advance!

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  2. #2
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Simba Code:
    function Distance(xs, ys, xe, ye:LongInt):LongInt

    built into Simba under Math

    "Sometimes User's don't need the Answer spelled out with Code. Sometimes all they need is guidance and explanation of the logic to get where they are going."

  3. #3
    Join Date
    Nov 2010
    Location
    Australia
    Posts
    1,472
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    I think this best suits what you're looking for(i havent tested it):
    http://docs.villavu.com/simba/script...samepointsatpa

    first get the two diff colors/combine into atpa, then do GetSamePointsATPA

    or do this:

    FindTPAEges of one color TPA(get the boundary TPA of one color)
    then do TPAinTPA(find the boundary TPA from before and check if its in the boudary of the second color)

  4. #4
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    I appreciate the suggestions. Thanks BraK but I already knew how to find distance, and that's kinda close to what I was looking for, KingKong, but not so much finding over-lapping TPAs.

    How about this...How would I find a box of, let's say, 20x20 containing those two colors within it? Also, if that box is found containing both colors, how would I find the bounds of it as long as every point within it?

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  5. #5
    Join Date
    Mar 2006
    Location
    Behind you
    Posts
    3,193
    Mentioned
    61 Post(s)
    Quoted
    63 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    how would I find the bounds of it as long as every point within it?
    Simba Code:
    GetTPABounds

    I might be reading that wrong it has bad wording.

    Quote Originally Posted by Flight View Post
    I appreciate the suggestions. Thanks BraK but I already knew how to find distance
    I misread your first post/skimmed through it.

    Combine the two TPAs then break it down into 20x20 boxes and search each box for the colors if you find the box with both colors then you have your box. if you want them to have a certain amount of each just use countcolor instead to get the amount in each and compare.

    "Sometimes User's don't need the Answer spelled out with Code. Sometimes all they need is guidance and explanation of the logic to get where they are going."

  6. #6
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by Flight View Post
    I appreciate the suggestions. Thanks BraK but I already knew how to find distance, and that's kinda close to what I was looking for, KingKong, but not so much finding over-lapping TPAs.

    How about this...How would I find a box of, let's say, 20x20 containing those two colors within it? Also, if that box is found containing both colors, how would I find the bounds of it as long as every point within it?
    Combine the two tpas and then use the distance function of your choice to change the tpa into an atpa. Sort through the new atpa by the amount of points you want using length(atpa[i]). I suggest debugging your object from different camera angles and finding the range of lengths the tpas have. I use this method for finding roaches. It is VERY accurate.

    Simba Code:
    function FindRoach(var P: TPoint): Boolean;
    var
      CTS, I, Len, C: Integer;
      TPA, TPA2, Temp, BTPA: TPointArray;
      ATPA, NATPA: Array of TPointArray;
      B, Mid: TBox;
      TP: TPoint;
    begin
      Result := False;
      ClearScreen;
      if not LoggedIn then Exit;
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.41, 0.83);//find wings
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, 2387585, MSX1, MSY1, MSX2, MSY2, 12);
      SetColorspeed2Modifiers(0.06, 0.27);//find body
      FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 1650514, MSX1, MSY1, MSX2, MSY2, 6);
      ColorToleranceSpeed(CTS);
      SetColorSpeed2Modifiers(0.2, 0.2);
      if (Length(TPA) < 1) or (Length(TPA2) < 1) then
      begin
        m_Debug('Roach - Found no colors', True);
        Exit;
      end;
      BTPA := CombineTPA(TPA, TPA2);//add them together
      ClearDoubleTPA(BTPA);
      ATPA := SplitTPA(BTPA, 7);//split into different

      SetLength(NATPA, Length(ATPA));
      C := 0;
      for i := 0 to High(ATPA) do
      begin
        Len := Length(ATPA[i]);
        if (Len < 300) then Continue;
        TP := MiddleTPA(ATPA[i]);
        if FindDeath(TP) then Continue;
        SortTPAFrom(ATPA[i], Point(MSCY, MSCY));
        NATPA[C] := ATPA[i];
        Inc(C);
        if Debug then
        begin
          B := GetTPABounds(ATPA[i]);
          SMART_DrawBoxEx(False, B, clWhite);
        end;
      end;
      SetLength(NATPA, C);

      SortATPAFromFirstPoint(ATPA, Point(MSCX, MSCY));
      //if Debug then DrawDotsMulti(False, NATPA);
      For i := High(NATPA) downto 0 do
      begin
        B := GetTPABounds(NATPA[i]);
        TP := MiddleTPA(NATPA[i]);
        if FindDeath(TP) then Continue;
        MMouse(TP.x, TP.y, 12, 12);
        If(WaitUpTextMulti(['ttack', 'ockroach', 'roach sol', 'soldier'], 550)) then
        begin
          Result := True;
          GetMousePos(P.x, P.y);
          if Debug then SMART_DrawBoxEx(False, B, clGreen);
          m_Debug('Roach - ', False);
          m_Debug('  Length: ' +ToStr(Length(NATPA[i])), False);
          m_Debug('  Bounds: ' +ToStr(GetTPABounds(NATPA[i])), False);
          Exit;
        end else
        begin
          if Debug then Smart_DrawBoxEx(False, B, clRed);
          m_Debug('Not Roach - ', False);
          m_Debug('  Length: ' +ToStr(Length(NATPA[i])), False);
          m_Debug('  Bounds: ' +ToStr(GetTPABounds(NATPA[i])), False);
        end;
      end;
    end;

  7. #7
    Join Date
    Nov 2006
    Posts
    2,369
    Mentioned
    4 Post(s)
    Quoted
    78 Post(s)

    Default

    mormonman I think he wants to make sure both colors exist. Comibing would not be solution to that.
    Quote Originally Posted by DeSnob View Post
    ETA's don't exist in SRL like they did in other communities. Want a faster update? Help out with updating, otherwise just gotta wait it out.

  8. #8
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Quote Originally Posted by BraK View Post
    Combine the two TPAs then break it down into 20x20 boxes and search each box for the colors if you find the box with both colors then you have your box. if you want them to have a certain amount of each just use countcolor instead to get the amount in each and compare.
    Now that sounds more like it! I've made a TPA for each color, combined them, and put that final TPA into a 2DPA (with a 20x20 bounds each). So with that being done I don't think checking those boxes for the existence of both colors will be necessary, because to make even one box it must find both colors.

    I'll play around with it for a while, do some debugging and let ya know what I come up with. If it's successful then that opens up many doors for me. Thank you very much for the help, Brak. Have some Repz.

    Edit:
    I'll come back to it after I spread some rep around...

    Edit2:
    Nevermind I was wrong. I will have to check each box for the existence of both colors. Any idea how to go about that?
    Last edited by Flight; 11-17-2011 at 10:48 AM.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  9. #9
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by weequ View Post
    mormonman I think he wants to make sure both colors exist. Comibing would not be solution to that.
    That's what the Length() check is for for both TPAs. If only one was found it would exit (its there in code). I use the same method to find the Furnace in Edgeville. You can also do a Length check as well with the combined TPA.

    What I do is look for the rarer color first, turn it into a ATPA with set parameters then get the bounds of the best ATPA (or get bounds of all) and search around those area(s) particularly for the next color. Then do a length check (you could do a length check on both before hand etc). Hasn't failed me yet.
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  10. #10
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    How is this looking for a start? If I'm doing something wrong then by all means tell me what should be changed:

    Simba Code:
    CTS := GetColorToleranceSpeed;
        ColorToleranceSpeed(2);
        FindColorsSpiralTolerance(MSCX, MSCY, TPA, ColorA, MSX1, MSY1, MSX2, MSY2, Tol);
        FindColorsSpiralTolerance(MSCX, MSCY, TPA2, ColorB, MSX1, MSY1, MSX2, MSY2, Tol);
        ColorToleranceSpeed(CTS);
        TPAF := CombineTPA(TPA, TPA2);
        TPAA := TPAToATPAEx(TPAF, Bounds, Bounds);
        SortATPASize(TPAA, True);
        for I := 0 To High(TPAA) do
        begin
          for H := 0 To High(TPA) do
          begin
            for J := 0 To High(TPA2) do
            begin
              if (PointInTPA(TPA[H], TPAA[i]) and PointInTPA(TPA[J], TPAA[i])) then
                Writeln('Success!');

    Edit:
    Here's a better version. Since I've already combined TPA and TPA2 into TPAF I can just check if a point from TPAF exists within the TPAA. If so, I go to the middle of that and presto, I have the box where the two colors meet within an amount of H/W bounds I define. Check it out: (Searching for the 'relations box' in which Color A/B exists within a 10x10 box)


    To:


    Simba Code:
    FindColorsSpiralTolerance(MSCX, MSCY, TPA, ColorA, MSX1, MSY1, MSX2, MSY2, Tol);
        FindColorsSpiralTolerance(MSCX, MSCY, TPA2, ColorB, MSX1, MSY1, MSX2, MSY2, Tol);
        ColorToleranceSpeed(CTS);
        TPAF := CombineTPA(TPA, TPA2);
        TPAA := TPAToATPAEx(TPAF, Bounds, Bounds);
        SortATPASize(TPAA, True);
        for I := 0 To High(TPAA) do
        begin
          for K := 0 To High(TPAF) do
          begin
            if PointInTPA(TPAF[K], TPAA[i]) then
            begin
              MiddleTPAEx(TPAA[i], X, Y);

    Another question, what's the function for adding a Point to a TPA?
    Last edited by Flight; 11-17-2011 at 12:42 PM.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


  11. #11
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You're over complicating the situation.

    Find the first color, split it into boxes or whatever. Then expand the boundaries of that box to do a 2nd search for the 2nd color in that new area.

  12. #12
    Join Date
    Sep 2007
    Location
    Michigan
    Posts
    3,862
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Something like this. This gives you all the areas its found this way.

    Simba Code:
    FindColorsTolerance(TPA, ColorA, x1, y1, x2, y2, tol);
      if Length(TPA) < 1 then
        Exit;
      ATPA := TPAtoATPAEx(TPA, W, H);
      L := High(ATPA);
      SetArrayLength(ATPA2, L+1);
      for i := 0 to L do
      begin
        B := GetTPABounds(ATPA[i]);
        with B do
          FindColorsTolerance(ATPA2[i], ColorB, x1-10, y1-10, x2+10, y2+10, tol);//<- customize the boundaries
      end;
    (Scripts outdated until I update for new SRL changes)
    AK Smelter & Crafter [SRL-Stats] - Fast Fighter [TUT] [SRL-Stats]
    If you PM me with a stupid question or one listed in FAQ I will NOT respond. -Narcle
    Summer = me busy, won't be around much.

  13. #13
    Join Date
    Aug 2007
    Location
    Colorado
    Posts
    7,421
    Mentioned
    268 Post(s)
    Quoted
    1442 Post(s)

    Default

    Quote Originally Posted by Narcle View Post
    Something like this. This gives you all the areas its found this way.

    Simba Code:
    FindColorsTolerance(TPA, ColorA, x1, y1, x2, y2, tol);
      if Length(TPA) < 1 then
        Exit;
      ATPA := TPAtoATPAEx(TPA, W, H);
      L := High(ATPA);
      SetArrayLength(ATPA2, L+1);
      for i := 0 to L do
      begin
        B := GetTPABounds(ATPA[i]);
        with B do
          FindColorsTolerance(ATPA2[i], ColorB, x1-10, y1-10, x2+10, y2+10, tol);//<- customize the boundaries
      end;
    Ah ha, that makes sense. This is pretty much what you were suggesting Wanted, yes? Thank you Narcle, I've a couple theories to try out today and this will definitely be on the list.

    Current projects:
    [ AeroGuardians (GotR minigame), Motherlode Miner, Blast furnace ]

    "I won't fall in your gravity. Open your eyes,
    you're the Earth and I'm the sky..."


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
  •