SRL Archive - Research & Development Lounge

FindClosestColor


Metagen

2007-11-01 16:20:35


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 :D

bullzeye95

2007-11-01 16:36:33

FindColorSpiralTolerance ;)

Metagen

2007-11-01 16:37:16

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

Metagen

2007-11-01 17:10:09

noob points 2 u :D

OK THE DIFFERENCE IS THIS

scars works in a box
mine works in a circle

Santa_Clause

2007-11-01 17:30:31

FindColorCircle…or does that search outwards in?

Shorter:

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.

Metagen

2007-11-01 17:51:13

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)

n3ss3s

2007-11-02 07:06:28

Sigh… FindColorsSpiral still.

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


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

Metagen

2007-11-02 08:00:23

Points for trying =\

n3ss3s

2007-11-02 08:09:56

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 :p I re-invented tolerance xD

Metagen

2007-11-02 08:25:14

-.- member forums

n3ss3s

2007-11-02 08:54:30

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