Advertisement
Janilabo

asd

Jan 6th, 2014
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.60 KB | None | 0 0
  1. function ExplodeBox(bx: TBox; rows, columns: integer): TBoxArray;
  2. var
  3.   r, c, w, h, ew, eh, ow, oh, i, x, y: integer;
  4. begin
  5.   if ((rows > 0) and (columns > 0) and (bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then
  6.   begin
  7.     w := ((bx.X2 - bx.X1) + 1);
  8.     h := ((bx.Y2 - bx.Y1) + 1);
  9.     if (rows < 1) then
  10.       rows := 1
  11.     else
  12.       if (rows > h) then
  13.         rows := h;
  14.     if (columns < 1) then
  15.       columns := 1
  16.     else
  17.       if (columns > w) then
  18.         columns := w;
  19.     w := (w div columns);
  20.     h := (h div rows);
  21.     ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
  22.     eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
  23.     SetLength(result, (rows * columns));
  24.     y := bx.Y1;
  25.     for r := 0 to (rows - 1) do
  26.     begin
  27.       x := bx.X1;
  28.       if ((eh > 0) and (r < eh)) then
  29.         oh := 1
  30.       else
  31.         oh := 0;
  32.       for c := 0 to (columns - 1) do
  33.       begin
  34.         if ((ew > 0) and (c < ew)) then
  35.           ow := 1
  36.         else
  37.           ow := 0;
  38.         i := ((r * columns) + c);
  39.         result[i].X1 := x;
  40.         result[i].X2 := (x + (w - 1) + ow);
  41.         result[i].Y1 := y;
  42.         result[i].Y2 := (y + (h - 1) + oh);
  43.         x := (Result[i].X2 + 1);
  44.       end;
  45.       y := (result[i].Y2 + 1);
  46.     end;
  47.   end else
  48.     SetLength(result, 0);
  49. end;
  50.  
  51. var
  52.   TBA: TBoxArray;
  53.   bx: TBox;
  54.   i, c: Integer;
  55.  
  56. begin
  57.   bx := intToBox(568, 213, 717, 458);
  58.   TBA := ExplodeBox(bx, 7, 4);
  59.   c := 0;
  60.   repeat
  61.     ClearDebug;
  62.     c := (c + 1);
  63.     for i := 0 to High(TBA) do
  64.       WriteLn(TBA[i]);
  65.     Status('Looped ' + IntToStr(c) + ' times!');
  66.   until False;
  67. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement