PDA

View Full Version : FindClosestColor



Metagen
11-01-2007, 08:20 PM
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
11-01-2007, 08:36 PM
FindColorSpiralTolerance ;)

Metagen
11-01-2007, 08:37 PM
No mines a little different, it wont change the x and y on you.

Metagen
11-01-2007, 09:10 PM
noob points 2 u :D

OK THE DIFFERENCE IS THIS

scars works in a box
mine works in a circle

Santa_Clause
11-01-2007, 09:30 PM
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
11-01-2007, 09:51 PM
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
11-02-2007, 11:06 AM
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
11-02-2007, 12:00 PM
Points for trying =\

n3ss3s
11-02-2007, 12:09 PM
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 (http://www.villavu.com/forum/showthread.php?t=13767?t=15233&highlight=Find+Bunch+Colors) :p I re-invented tolerance xD

Metagen
11-02-2007, 12:25 PM
-.- member forums

n3ss3s
11-02-2007, 12:54 PM
Oh sorry, anyways its a function that has the colors and a for loop, in other words, tolerance xD