Boreas
2010-03-05 12:58:33
So I made the 'framework' of a function, and it's missing the 'payload' if you know what I mean. Let me know which payload you think is best. Also feel free to point out errors, or use it for your own payload.
This function makes a box to look in, with your choice of width and height, around your starting point (for example half the tile size on MS, around MSCX MSCY). It then looks in that box for something (the payload), and if it doesn't find it there, it looks in another box, spiralling out around the starting point, until it has looked all over the target area (for example MS).
The payload would consist of looking for an array of colors in the current box. Each color in the array would have its own tolerance (or tol and hmod smod for CTS2Modifiers), criteria such as minimum count/density.
Now once it gets to a box that has those colors with those critera, it could just stop there and return the box. Or it could return an array of all the boxes in the target area that meet those criteria (and if so, sorted by distance from start point, or by how much they met the criteria). Or stop looking once the array got to a certain length. It could also be a FindObj function where you also give it a text parameter, and it finds the first good box that also passes an uptext/chooseoption check, possibly doing the Mouse for you.
Each way of giving a result varies in speed and accuracy, what do you think is the best balance?
This function makes a box to look in, with your choice of width and height, around your starting point (for example half the tile size on MS, around MSCX MSCY). It then looks in that box for something (the payload), and if it doesn't find it there, it looks in another box, spiralling out around the starting point, until it has looked all over the target area (for example MS).
The payload would consist of looking for an array of colors in the current box. Each color in the array would have its own tolerance (or tol and hmod smod for CTS2Modifiers), criteria such as minimum count/density.
Now once it gets to a box that has those colors with those critera, it could just stop there and return the box. Or it could return an array of all the boxes in the target area that meet those criteria (and if so, sorted by distance from start point, or by how much they met the criteria). Or stop looking once the array got to a certain length. It could also be a FindObj function where you also give it a text parameter, and it finds the first good box that also passes an uptext/chooseoption check, possibly doing the Mouse for you.
Each way of giving a result varies in speed and accuracy, what do you think is the best balance?
program new;
function BoxInBoxAll(SmallBox, BigBox: Tbox): boolean;
begin
if PointInBox(Point(SmallBox.x1,SmallBox.y1), BigBox) then
if PointInBox(Point(SmallBox.x1,SmallBox.y2), BigBox) then
if PointInBox(Point(SmallBox.x2,SmallBox.y1), BigBox) then
if PointInBox(Point(SmallBox.x2,SmallBox.y2), BigBox) then
result := true;
end;
function CommonBox (Box1, Box2: TBox):TBox;
var tmparr: tintegerarray;
begin
tmparr:= [Box1.x1,Box1.x2,Box2.x1,Box2.x2];
QuickSort(tmparr);
result.x1:=tmparr[1];
result.x2:=tmparr[2];
tmparr:= [Box1.y1,Box1.y2,Box2.y1,Box2.y2];
QuickSort(tmparr);
result.y1:=tmparr[1];
result.y2:=tmparr[2];
if not PointInBox(point((result.x1+result.x2)/2,(result.y1+result.y2)/2),Box1) then
begin
result.x1:=0;
end;
end;
function FixBoxBounds (var SmallBox:Tbox; BigBox:Tbox):boolean;
begin
SmallBox := CommonBox(SmallBox,BigBox);
if SmallBox.x1 >0 then
result := true;
end;
{Look for an array of colors, with conditions like all colors or some, count per box, denisity within splitatpa bounds, etc
Choices:
FindObj- give it a text parameter
1 Once it finds a box meeting count/density/etc criteria it looks for uptext/chooseoption, trying another box if text is false
FindColors- no text
2 Returns first box that meets criteria
3 Returns first _IntegerParameter_ boxes that meet criteria in array sorted by StartPoint
4 Returns first _IntegerParameter_ boxes that meet criteria in array sorted by how well they meet criteria
5 Returns all boxes that meet criteria in Area sorted by StartPoint
6 Returns all boxes that meet criteria in Area sorted by how well they meet criteria
}
function SpiralBoxColors{Insert name here} ({Insert Color searching params and result here} StartPoint: tpoint; BoxWidth, BoxHeight:integer; Area:Tbox):boolean;
var
dirs: tstringarray;
AtBounds, dir, i, i2: integer;
TheBox: tbox;
begin
dirs := ['l', 'u', 'r', 'd'];
dir := 0;
i:=2;
TheBox:= IntToBox(StartPoint.x-round(BoxWidth/2),StartPoint.y-round(BoxHeight/2),
StartPoint.x+round(BoxWidth/2),StartPoint.y+round(BoxHeight/2));
repeat
if not BoxInBoxAll(TheBox, Area) then
begin
if not FixBoxBounds(TheBox, Area) then
begin
AtBounds := AtBounds or round(pow(2,dir));
if AtBounds = 15 then
exit;
end;
end;
if BoxInBoxAll(TheBox, Area) then
begin
{do color searches in TheBox here}
end;
if i2 = (i div 2) then
begin
i2:=0;
inc(dir);
if dir = 4 then
dir :=0;
inc(i)
end;
case Dirs[dir] of
'l':
begin
TheBox.x1 := TheBox.x1 - BoxWidth;
TheBox.x2 := TheBox.x2 - BoxWidth;
end;
'u':
begin
TheBox.y1 := TheBox.y1 - BoxHeight;
TheBox.y2 := TheBox.y2 - BoxHeight;
end;
'r':
begin
TheBox.x1 := TheBox.x1 + BoxWidth;
TheBox.x2 := TheBox.x2 + BoxWidth;
end;
'd':
begin
TheBox.y1 := TheBox.y1 + BoxHeight;
TheBox.y2 := TheBox.y2 + BoxHeight;
end;
end;
inc(i2);
until AtBounds = 15;
end;
begin
end.