• Sky
• Blueberry
• Slate
• Blackcurrant
• Watermelon
• Strawberry
• Orange
• Banana
• Apple
• Emerald
• Chocolate
• Charcoal

# FindColorLength [Request]

## Recommended Posts

Hello. Today i made a function called FindColorLength, as i needed this method in one of my scripts. I think many would make use of it. I really dont know if it's already here but here it is:

[sCAR]

function FindColorLength(var x, y: Integer; Color, xs, ys, xe, ye, tol, Length_: Integer): Boolean;

var

TPA: TPointArray;

ATPA: T2DPointArray;

begin

FindColorsTolerance(TPA, Color, xs, ys, xe, ye, tol)

ATPA := SplitTPA(TPA, 2);

SortATPABySize(ATPA);

InvertATPA(ATPA);

if Length(ATPA) = 0 then begin

result := False;

exit;

end;

if Length(ATPA[0]) > Length_ then begin

SetArrayLength(ATPA, 1);

Result := True;

end else begin

Result := False;

exit;

end;

x := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].X;

y := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].Y;

end;

[/sCAR]

Length_ = The required amount of colors in the ATPA. If the length of any ATPAs is lower than Length_ it will return false.

You can just set length to 0 if you just want the ATPA with the highest amount of colors, and use it as a 1 line code for that :-)

EDIT: Just found out the MMX1, MMY1... Takes something of the things around it but FindMMColorsTolerance doesn't so heres one for MM:

[sCAR]

function FindMMColorLength(var x, y: Integer; Color, tol, Length_: Integer): Boolean;

var

TPA: TPointArray;

ATPA: T2DPointArray;

begin

FindMMColorsTolerance(TPA, Color, tol)

ATPA := SplitTPA(TPA, 2);

SortATPABySize(ATPA);

InvertATPA(ATPA);

if Length(ATPA) = 0 then begin

result := False;

exit;

end;

if Length(ATPA[0]) > Length_ then begin

SetArrayLength(ATPA, 1);

Result := True;

end else begin

Result := False;

exit;

end;

x := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].X;

y := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].Y;

end;

[/sCAR]

Edited by sjesper

##### Share on other sites
Hello. Today i made a function called FindColorLength, as i needed this method in one of my scripts. I think many would make use of it. I really dont know if it's already here but here it is:

[sCAR]

function FindColorLength(var x, y: Integer; Color, xs, ys, xe, ye, tol, Length_: Integer): Boolean;

var

TPA: TPointArray;

ATPA: T2DPointArray;

begin

FindColorsTolerance(TPA, Color, xs, ys, xe, ye, tol)

ATPA := SplitTPA(TPA, 2);

SortATPABySize(ATPA);

InvertATPA(ATPA);

if Length(ATPA) = 0 then begin

result := False;

exit;

end;

if Length(ATPA[0]) > Length_ then begin

SetArrayLength(ATPA, 1);

Result := True;

end else begin

Result := False;

exit;

end;

x := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].X;

y := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].Y;

end;

[/sCAR]

Length_ = The required amount of colors in the ATPA. If the length of any ATPAs is lower than Length_ it will return false.

You can just set length to 0 if you just want the ATPA with the highest amount of colors, and use it as a 1 line code for that :-)

EDIT: Just found out the MMX1, MMY1... Takes something of the things around it but FindMMColorsTolerance doesn't so heres one for MM:

[sCAR]

function FindMMColorLength(var x, y: Integer; Color, tol, Length_: Integer): Boolean;

var

TPA: TPointArray;

ATPA: T2DPointArray;

begin

FindMMColorsTolerance(TPA, Color, tol)

ATPA := SplitTPA(TPA, 2);

SortATPABySize(ATPA);

InvertATPA(ATPA);

if Length(ATPA) = 0 then begin

result := False;

exit;

end;

if Length(ATPA[0]) > Length_ then begin

SetArrayLength(ATPA, 1);

Result := True;

end else begin

Result := False;

exit;

end;

x := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].X;

y := ATPA[0][Random(Length(ATPA[Random(Length(ATPA))]))].Y;

end;

[/sCAR]

Are you just counting then umber oftimes a color was found? You can use the CountColor() Function or CountColorTolerance() Which will return the number of times a color was found in a search area.

[scar]

Program New;

Var

II: Integer;

begin

II := CountColor(clBlack,0,0,RSPW,RSPH);

If II < 10 then

Writeln('Less than 10 pixels of color was found')

else

Writeln('More than 10 pixels of color was found');

end.

[/scar]

##### Share on other sites

I don't understand what this is supposed to do

##### Share on other sites
Are you just counting then umber oftimes a color was found? You can use the CountColor() Function or CountColorTolerance() Which will return the number of times a color was found in a search area.

[scar]

Program New;

Var

II: Integer;

begin

II := CountColor(clBlack,0,0,RSPW,RSPH);

If II < 10 then

Writeln('Less than 10 pixels of color was found')

else

Writeln('More than 10 pixels of color was found');

end.

[/scar]

Hmm i dont think you understand it.

I made it for finding a object that have the same color as other small objects on the screen. It it works really good at it.

It find all colors and put it into a TPA. Then does it split them so it have 1 object in ATPA[0] 1 object in ATPA[1] and so on... Then does it sort them all by size so the one with most colors come last and then invert them so the one with most colors come first.

It does then see if the one with most points have the requird amount of colors (This can be set to 0 for just sorting). and then output a random point at that object (ATPA).

I hope you understand it now.

##### Share on other sites

Oh alright gotcha. =p. I ported over the findobjrecord function in ubex so you can use ACA's FindObjRecord creator and it wokrs really good, uses RGB values, Tol, hue and sat and as long as your colors are good it will hit the object your looking for take a peak at it =p

##### Share on other sites
I made it for finding a object that have the same color as other small objects on the screen. It it works really good at it.

Not sure if that's what you're trying to do, but FindColoredAreaTolerance actually allows you to find an area of connected pixels with the same color, and allows you to specify the minimum amount of pixels.

##### Share on other sites
Oh alright gotcha. =p. I ported over the findobjrecord function in ubex so you can use ACA's FindObjRecord creator and it wokrs really good, uses RGB values, Tol, hue and sat and as long as your colors are good it will hit the object your looking for take a peak at it =p

Oh yeah, pretty nice and usefull function for later use :-), but i needed this because i had some objects on the minimap that had the exact same color as the object i wanted to use.

Not sure if that's what you're trying to do, but FindColoredAreaTolerance actually allows you to find an area of connected pixels with the same color, and allows you to specify the minimum amount of pixels.

Well it's like a advanced version of FindColoredAreaTolerance. FindColoredAreaTolerance find the same pixel all the time (When just searching from the same spot to the same spot), when my method find a random point at the object.

If FindColoredAreaTolerance find a point with more then the MinPix it return that point and stop the search. My method find all the objects with the amount of colors req and return the one with most colors, huge difference here.

It really dont think there is function like this, and i think it is pretty usefull.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×