Originally Posted by
VillaVuFTW
ExplodeBox is a way without smart, to detect the parameters of a given box, or target..
Example : ExplodeBox(IntToBox(200, 40, 300, 80);
Would set the search function if called, in between those given points.. sort of like a mousebox, but this draws a search around the particular "ExplodeBox".. I'm sorry I'm no advanced simba user, to put this into advanced terms
Below is something for you guys!
Small (basic) snippet for "Box Explosion" - exploding box to TBoxArray (by rows and columns):
Code:
const
BITMAP_WIDTH = 500;
BITMAP_HEIGHT = 500;
MAIN_BOX_X1 = 100;
MAIN_BOX_Y1 = 200;
MAIN_BOX_X2 = 400;
MAIN_BOX_Y2 = 300;
EXPLOSION_ROWS = 10;
EXPLOSION_COLUMNS = 30;
RANDOM_COLORS = True;
function ExplodeBox(bx: TBox; rows, columns: integer): TBoxArray;
var
r, c, w, h, ew, eh, ow, oh, i, x, y: integer;
begin
if ((rows > 0) and (columns > 0) and (bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then
begin
w := ((bx.X2 - bx.X1) + 1);
h := ((bx.Y2 - bx.Y1) + 1);
if (rows > h) then
rows := h;
if (columns > w) then
columns := w;
w := (w div columns);
h := (h div rows);
ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
SetLength(Result, (rows * columns));
y := bx.Y1;
for r := 0 to (rows - 1) do
begin
x := bx.X1;
if ((eh > 0) and (r < eh)) then
oh := 1
else
oh := 0;
for c := 0 to (columns - 1) do
begin
if ((ew > 0) and (c < ew)) then
ow := 1
else
ow := 0;
i := ((r * columns) + c);
Result[i].X1 := x;
Result[i].X2 := (x + (w - 1) + ow);
Result[i].Y1 := y;
Result[i].Y2 := (y + (h - 1) + oh);
x := (Result[i].X2 + 1);
end;
y := (Result[i].Y2 + 1);
end;
end else
SetLength(Result, 0);
end;
var
b: TBoxArray;
h, i, m, bmp: integer;
p, e: TPointArray;
begin
bmp := CreateBitmap(BITMAP_WIDTH, BITMAP_HEIGHT);
DisplayDebugImgWindow(BITMAP_WIDTH, BITMAP_HEIGHT);
DrawBitmapDebugImg(bmp);
b := ExplodeBox(IntToBox(MAIN_BOX_X1, MAIN_BOX_Y1, MAIN_BOX_X2, MAIN_BOX_Y2), EXPLOSION_ROWS, EXPLOSION_COLUMNS);
h := High(b);
if RANDOM_COLORS then
m := 1;
case m of
0:
for i := 0 to h do
begin
p := TPAFromBox(b[i]);
FindTPAEdgesWrap(p, e);
DrawTPABitmap(bmp, e, 255);
SetLength(e, 0);
end;
1:
for i := 0 to h do
begin
p := TPAFromBox(b[i]);
FindTPAEdgesWrap(p, e);
DrawTPABitmap(bmp, e, Random(16777216));
SetLength(e, 0);
end;
end;
DrawBitmapDebugImg(bmp);
end.
Made small update for ExplodeBox too, as it had couple unneeded checks (for rows < 1 and columns < 1) that I forgot to remove in past..
Sorry about offtopic :3