SRL Archive - Help and Support

Shortest Distance from center of screen?


itSchRis917

2008-05-09 00:12:48

Ok, well i just recently got back into scripting and i dont remember a whole lot, so i was wondering if someone would be willing to help me out..

Currently i have a procedure that finds a color and stores that color into a TPointArray and splits it up using TPAtoATPAEx but now i want to know how to take all of those points and compare the distances from the center of the main screen. When it finds the one with the shortest distance i want it to check it to see if it is the right object and if it is not, to proceed onto the next point.. I know how to do everything except comparing the distance of the points… Help is greatly appreciated. :)

bullzeye95

2008-05-09 00:33:56

SortTPAFrom(TPA, Point(MSCX, MSCY));
Then just loop through the points and check each one.

itSchRis917

2008-05-09 00:36:40

Ahhh thank you very much.

Sir R. M8gic1an

2008-05-09 02:29:57

or instead of using a FindColorsTolerance you could use FindColorsSpiralTolerance and make it start from the middle of the screen.

~RM

R0b0t1

2008-05-09 23:24:52


Dist({ forgot params });

bullzeye95

2008-05-10 01:22:20

Actually, it's Distance(x1, y1, x2, y2); =]

Sumilion

2008-05-10 04:17:37

When you use TPAtoATPA(ex) it is best to use FindColorsSpiralTolerance(MSCX, MSCY, color, x1, y1, x2, y2, tol); However when you use SplitTPA(ex) it messes with the order of points so eventhough the point in the TPA are ordened, SplitTPA messes that up, so FindColorsSpiralTolerance won't help there. You could use SortATPAFrom(T2DPointArray, Point(MSCX, MSCY)); but in my experience that is not working well. What I do, I make another TPointArray, with the center of each found object (made by SplitTPA) and the perform a SortTPAFrom(TPA, Point(MSCX, MSCY)); on it. That works better for me.

But you're using TPAtoATPA so you should just use FindColorsSpiralTolerance :p

itSchRis917

2008-05-10 08:52:13

ooo Sumilion.. i like your idea… Interesting…

n3ss3s

2008-05-10 11:20:45

Sumilion is right, SortATPAFrom actually does half of the sorting an ATPA from a point; It sorts the TPAs in the ATPA from the point but not the ATPA itself…

Sumilion

2008-05-10 11:31:12

From: n3ss3s
Sumilion is right, SortATPAFrom actually does half of the sorting an ATPA from a point; It sorts the TPAs in the ATPA from the point but not the ATPA itself…


Ah see I didn't know that :p

n3ss3s

2008-05-10 12:42:13

I'm too lazy to do it atm, but you can simply make it truly sort from the point if you first do SortATPAFrom and then, use the BubbleSort algorithm with Freddy's new Swap function that can swap anything of the same type, using the distance instead of the size of the int…

itSchRis917

2008-05-10 13:09:53

Ok guys, that problem is solved.. But now i have another question.. I'm searching for the object with a specific color with a tolerance, using FindColorsSpiralTolerance.. I would like to know if it is possible to list all of the colors it finds and puts into the array. I would like to display this as a writeln, for a debug function for my benefit. Please let me know if this is possible.

munk

2008-05-10 13:22:37


intArray := getColors(TPA);

thatll make a list of all the colors. You can use

clearSameIntegers(intArray);
to clear duplicate colors

I was wondering why sortATPAfrom wasnt working right for me. I really like your idea Sum, and im going to borrow it ;)

itSchRis917

2008-05-10 13:25:01

I know that part munk, but is there any way to convert an integer array to a string?? so i can put it into a Writeln?

n3ss3s

2008-05-10 13:29:38

Come on, try harder!

Just go through the array in a for loop doing Writeln(IntToStr(Arr))…

itSchRis917

2008-05-10 13:33:42

Yeah.. lol i did it a different way, but that way would work.

Negaal

2008-05-12 13:22:22

Ok, I'll try, but I don't got no scar to test…


function Find_Nearest_To_XY(cx, cy : Integer; TPA : TPointArray) : TPoint;
var
I, L, D, Index, C : integer;
begin
L := High(TPA)
D := Distance(cx, cy, TPA[0].x, TPA[0].y) + 1;
For I:=0 to L do
begin
C := D;
D := Min(Distance(cx, cy, TPA[I].x, TPA[I].y), D);
If (C > D) then Index := D;
end;
Result := TPA[Index];
end;

Pretty sure it gives an error, but you can try;)