Results 1 to 10 of 10

Thread: Removing a point from a TPA if it matches a color

  1. #1
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default Removing a point from a TPA if it matches a color

    I'm trying to sort through a TPA and remove a point if it matches a color within a certain tolerance. I tried doing it manually with a few loops but that didn't work, and I don't see anything in the wizzyplugin that would help me out. Any ideas?

  2. #2
    Join Date
    Feb 2008
    Posts
    517
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    n = integer
    for i := 0 to high(array) do
    begin
    if not array.color is somehow(within tolerance) then n = n + 1;
    newarray[n] = array[i]
    end


    something to that extent if it made sense, just have a loop with another integer in it that will have index for a new array which will replace the old one

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

    Default

    Simba Code:
    function RemoveLikeColorsTPA(Color, Tolerance: Integer; TPA: TPointArray): TPointArray;
    var
      NewArray: TPointArray;
      i, Index, Hi, Color1: Integer;
    begin
      if Length(TPA) < 1 then Exit;
      SetLength(NewArray, Length(TPA));
      Hi := High(TPA);
      Index := 0;

      for i := 0 to Hi do
      begin
        Color1 := GetColor(TPA[i].x, TPA[i].y);
        if not SimilarColors(Color1, Color, Tolerance) then
        begin
          NewArray[Index] := TPA[i];
          Inc(Index);
        end;
      end;
      SetLength(NewArray, Index);
      Result := NewArray;
    end;

    Edit: read the first post wrong.
    Last edited by mormonman; 01-23-2011 at 11:33 PM.

  4. #4
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Simba Code:
    function RemoveLikeColorsTPA(Color, Tolerance: Integer; TPA: TPointArray): TPointArray;
    var
      NewArray: TPointArray;
      i, Index, h, Color1: Integer;
    begin
      if Length(TPA) < 1 then
        exit;
      h := High(TPA);

      for i := 0 to h do
      begin
         := GetColor(TPA[i].x, TPA[i].y);
        if SimilarColors(Color, GetColor(TPA[i].x, TPA[i].y), Tolerance) then
        begin
          swap(TPA[High(TPA)], TPA[i]);
          SetArrayLength(TPA, GetArrayLength(TPA - 1));
        end;
      end;
      Result := TPA;
    end;
    Should work?
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

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

    Default

    Simba Code:
    function RemoveLikeColorsTPA(Color, Tolerance: Integer; TPA: TPointArray): TPointArray;
    var
      cols: TIntegerArray;
      i, h, L: Integer;
    begin
      if Length(TPA) < 1 then
        exit;
      h := High(TPA);
      SetLength(Result, h+1);

      cols := getColors(TPA);

      L := 0;
      for i := 0 to h do
      begin
        if (not SimilarColors(Color, cols[i], Tolerance)) then
        begin
          // if the colour is not similar, add the index into the array.
          Result[L] := TPA[i];
          Inc(L);
        end;
     
      SetLength(Result, L);
    end;

    Should be significantly faster then others posted.

    Only grabs the client ONCE, rather than every time. Also, it does not do memory management every time a colour is valid, instead it only allocates then copies it over once.
    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
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    To use this practically you'd have to do it like this:

    SCAR Code:
    {.include SRL/SRL.scar}
    {.include SRL/SRL/misc/debug.scar}

    type
      TColorPointArray = record
        Points: TPointArray;
        Colors: TIntegerArray;
      end;

    function FindTCPA(var TCPA: TColorPointArray; Color, xs, ys, xe, ye, Tol: Integer): Boolean;
    begin
      Result := FindColorsTolerance(TCPA.Points, Color, xs, ys, xe, ye, Tol);
      if (not (Result)) then
        Exit;
      TCPA.Colors := GetColors(TCPA.Points);
    end;

    function RemoveColorsInTPA(TCPA: TColorPointArray; Color: LongInt): TColorPointArray;
    var
      H, I, L: LongInt;
    begin
       H := High(TCPA);
       for I := 0 to H do
         if (TCPA.Colors[I] <> Color) then
         begin
           Inc(L);
           SetLength(Result, L);
           Result.Points[L - 1] := TCPA.Points[I];
           Result.Colors[L - 1] := TCPA.Colors[I];
         end;
    end;

    function RemoveColorsInTPATol(TCPA: TColorPointArray; Color, Tol: LongInt): TColorPointArray;
    var
      H, I, L: LongInt;
    begin
       H := High(TCPA);
       for I := 0 to H do
         if (not (SimilarColors(TCPA.Colors[I], Color, Tol))) then
         begin
           Inc(L);
           SetLength(Result, L);
           Result.Points[L - 1] := TCPA.Points[I];
           Result.Colors[L - 1] := TCPA.Colors[I];
         end;
    end;

    var
      TCPA: TColorPointArray;

    begin
      SetUpSRL;
      ActivateClient;
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.2, 0.2);
      FindTCPA(TCPA, 12344556, MSX1, MSY1, MSX2, MSY2, 5);
      RemoveColorsInTPATol(TCPA, 1235932, 5);
      SetColorspeed2Modifiers(0.2, 0.2);
      ColorToleranceSpeed(1);
      DebugTPA(TCPA.Points, '');
    end.

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

    Default

    Quote Originally Posted by IceFire908 View Post
    To use this practically you'd have to do it like this:

    SCAR Code:
    //..snip
    Why? o.O What was wrong with my solution?
    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

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

    Default

    Quote Originally Posted by Nava2 View Post
    Why? o.O What was wrong with my solution?
    Well you ninja'd me technically.

    But really a TPA is only a recording of points, if you take the same points and apply it to a TPA of a different time period in coordination with getcolors you're not working with the original colors, it's important to record the colors at the same time you record the points, hence the purpose of TColorPointArray and FindTCPA.

  9. #9
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by IceFire908 View Post
    Well you ninja'd me technically.

    But really a TPA is only a recording of points, if you take the same points and apply it to a TPA of a different time period in coordination with getcolors you're not working with the original colors, it's important to record the colors at the same time you record the points, hence the purpose of TColorPointArray and FindTCPA.
    This is true, but for the purpose I would be using it for I would using it for, the objects (bankers) don't move. So, under normal circumstances, yes yours would be better, but I'll probably use one of the other, less script-bloating solutions.


    Edit:
    Also, I meant to post this before I left but i guess i missed the "submit reply" button

    Simba Code:
    function FilterPointsColorTolerance(Color, Tolerance: LongInt; TPA: TPointArray): TPointArray;
    var
      i, j, x, y: Integer;
    begin
      for i := 0 to High(TPA) do
        if not(FindColorTolerance(x, y, Color, TPA[i].x, TPA[i].y, TPA[i].x, TPA[i].y, Tolerance)) then
        begin
          SetLength(Result, Length(Result) + 1);
          Result[High(Result)] := TPA[i];
        end;
    end;

  10. #10
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    Tom, yours really is much slower and if the TPA is big it'll lag.

    + rep to Nava & Ice

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

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
  •