SRL Archive - SRL Archives

function IsColorInArray


Roberty Bob

2006-07-01 06:18:19

I couldn't find anything to do this in SRL. I know it is simple :). But I think it is quite useful.

One example useage: In my autocolor procedure, I use this to check colors against a "blacklist" array of colors. I have a triple iteractive searach process with an increasing searchbox size and tolerance while stepping through a reference color array.
IsColorInArray performs a quick quick whether a color is blacklisted before proceeding in the AutoColor function.

I've attached a demonstration of its useage. :D ENJOY.

[PHP]
{*******************************************************************************
function IsColorInArray (var TheColor:integer ; TheArray: array of Integer; ArraySize:integer):boolean;
By: Roberty Bob
Description: Returns true if the specified color is found in the array.
*******************************************************************************}
function IsColorInArray (var TheColor:integer ; TheArray: array of Integer; ArraySize:integer):boolean;
var
ColorFound: boolean;
var
i: integer;

begin
ColorFound:= false;
i:= 0;

repeat
if TheArray= TheColor then
begin
ColorFound:= true;
break;
end;
i:= i+1;
until i = (ArraySize)

result:= ColorFound;
end;
[/PHP]

Bego

2006-07-01 12:39:46

Thanks for contributing.

I don't really find a use for that, but there is some kind of use, good job.

realrune

2006-07-01 21:36:00

Try this instead :

function IsColorInArray (TheColor : integer; TheArray: array of Integer) : boolean;
var
i: integer;

begin
i:= 0;

repeat
if TheArray[i]= TheColor then
begin
Result := true;
break;
end;
i:= i+1;
until i = (GetArrayLength(TheArray) - 1);

end;

Basically does the same thing, but with less code and you don't need to input the array length.

masquerader

2006-07-01 23:21:29

oww,
for loops roxors my soxors

function IsColorInArray (TheColor : integer; TheArray: array of Integer) : boolean;
var
i: integer;
begin
for i:=0 to GetArrayLength(TheArray) - 1 do
if(TheArray[i]= TheColor)then
begin
result:=true;
break;
end;
end;

you wrote an entire thing to test this??

thats cool….. i guess..

WhiteShadow

2006-07-02 01:49:15

Your very talented! Keep up the great work!