Results 1 to 11 of 11

Thread: FindClosestColor

  1. #1
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default FindClosestColor

    SCAR Code:
    function FindClosestColor(var cx,cy : integer; Color, OriginX, OriginY, MaxDist, Tol : integer): Boolean;
    var
    CPX, CPY, PX, PY, Dist : integer;
    begin
     Dist := MaxDist+1;
     For PX := OriginX-MaxDist to OriginX+MaxDist do
     begin
       For PY := OriginY-MaxDist to OriginY+MaxDist do
       begin
         If Distance(PX,PY,OriginX,OriginY) < Dist then
         begin
           If SimilarColors(GetColor(PX, PY), Color, Tol) then
           begin
             CPX := PX;
             CPY := PY;
             Dist := Distance(PX,PY,OriginX,OriginY);
             MaxDist := Dist;
           end;
         end;
       end;
     end;
     If CPX <> 0 then
     begin
       cx := CPX;
       cy := CPY;
       result := True;
     end else
     begin
      result := False;
     end;
    end;
    I wrote this function. basically you give it an origin point, and it returns the closest colored point within tolerance range to the origin. (tested it in paint works nicely). I dont know if a function like this already exists (i checked the srl and scar manuals didnt see one). tell me what you think and make sure to give me credits if you use it

    -it returns the closest point within a distance of the x,y. it works in a circle
    ~ Metagen

  2. #2
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    FindColorSpiralTolerance

  3. #3
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    No mines a little different, it wont change the x and y on you.
    ~ Metagen

  4. #4
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    noob points 2 u

    OK THE DIFFERENCE IS THIS

    scars works in a box
    mine works in a circle
    ~ Metagen

  5. #5
    Join Date
    Nov 2006
    Location
    NSW, Australia
    Posts
    3,487
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    FindColorCircle...or does that search outwards in?

    Shorter:

    SCAR Code:
    function FindClosestColor(var cx,cy : integer; Color, OriginX, OriginY, MaxDist, Tol : integer): Boolean;
    var
    CPX, CPY, PX, PY, Dist : integer;
    begin
     Dist := MaxDist+1;
     For PX := OriginX-MaxDist to OriginX+MaxDist do
       For PY := OriginY-MaxDist to OriginY+MaxDist do
         If Distance(PX,PY,OriginX,OriginY) < Dist then
           If SimilarColors(GetColor(PX, PY), Color, Tol) then
           begin
             CPX := PX;
             CPY := PY;
             Dist := Distance(PX,PY,OriginX,OriginY);
             MaxDist := Dist;
           end;
     If CPX <> 0 then
     begin
       cx := CPX;
       cy := CPY;
       result := True;
     end;
    end

    Dang...I hate standards when you have so many if/then and for/to/do statements.
    [CENTER][img]http://signatures.mylivesignature.com/54486/113/4539C8FAAF3EAB109A3CC1811EF0941B.png[/img][/CENTER]
    [CENTER][BANANA]TSN ~ Vacation! ~ says :I Love Santy[/BANANA][/CENTER]

    [CENTER][BANANA]Raymond - Oh rilie? says :Your smart[/BANANA][/CENTER]

  6. #6
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    it searches left to right

    But it only returns the very closest point. it goes through every point in the alloted area, and then if it finds a closer point on the way in, it will search in that aloted area as that as the maximum radius

    and it had a maximum distance so that you can set the radius to 5 and itll draw you a nice perfect circle (in paint)
    ~ Metagen

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

    Default

    Sigh... FindColorsSpiral still.

    And if you dont want change the X and Y, do

    SCAR Code:
    Function ShittyFindColorSpiral(Var X, Y : Integer; FromX, FromY, Color, x1, y1, x2, y2, Tol: Integer): Boolean;
    Var
      Dx, Dy: Integer;
    Begin
      Dx := FromX;
      Dy := FromY;
      Result := FindColorSpiralTolerance(Dx, Dy, Color, x1, y1, x2, y2, Tol);
      If Result Then
      Begin
        X := Dx;
        Y := Dy;
      End;
    End;

    Good job though..

  8. #8
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Points for trying =\
    ~ Metagen

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

    Default

    Yes indeed, I am definetly not saying that your function is bad or anything, its just been invented before.

    But dont worry, thats happened to other people too:

    Me making history I re-invented tolerance xD

  10. #10
    Join Date
    Jul 2007
    Location
    Ottawa, Canada
    Posts
    930
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    -.- member forums
    ~ Metagen

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

    Default

    Oh sorry, anyways its a function that has the colors and a for loop, in other words, tolerance xD

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
  •