Janilabo

box explosion

Aug 17th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.58 KB | None | 0 0
  1. const
  2.   BITMAP_WIDTH = 500;
  3.   BITMAP_HEIGHT = 500;
  4.  
  5.   MAIN_BOX_X1 = 100;
  6.   MAIN_BOX_Y1 = 200;
  7.   MAIN_BOX_X2 = 400;
  8.   MAIN_BOX_Y2 = 300;
  9.  
  10.   EXPLOSION_ROWS = 10;
  11.   EXPLOSION_COLUMNS = 30;
  12.  
  13. {==============================================================================]
  14.   Explanation: Sets points from TPA that are inside bmp as color.
  15. [==============================================================================}
  16. procedure SetPixels(bmp: Integer; TPA: TPointArray; color: Integer);
  17. var
  18.   a, z, w, h: Integer;
  19. begin
  20.   z := High(TPA);
  21.   if (z > -1) then
  22.   begin
  23.     GetBitmapSize(bmp, w, h);
  24.     for a := 0 to z do
  25.       if ((TPA[a].X >= 0) and (TPA[a].Y >= 0) and (TPA[a].X < w) and (TPA[a].Y < h)) then
  26.         FastSetPixel(bmp, TPA[a].X, TPA[a].Y, color);
  27.   end;
  28. end;
  29.  
  30. function ExplodeBox(bx: TBox; rows, columns: integer): TBoxArray;
  31. var
  32.   r, c, w, h, ew, eh, ow, oh, i, x, y: integer;
  33. begin
  34.   if ((rows > 0) and (columns > 0) and (bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then
  35.   begin
  36.     w := ((bx.X2 - bx.X1) + 1);
  37.     h := ((bx.Y2 - bx.Y1) + 1);
  38.     if (rows < 1) then
  39.       rows := 1
  40.     else
  41.       if (rows > h) then
  42.         rows := h;
  43.     if (columns < 1) then
  44.       columns := 1
  45.     else
  46.       if (columns > w) then
  47.         columns := w;
  48.     w := (w div columns);
  49.     h := (h div rows);
  50.     ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
  51.     eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
  52.     SetLength(Result, (rows * columns));
  53.     y := bx.Y1;
  54.     for r := 0 to (rows - 1) do
  55.     begin
  56.       x := bx.X1;
  57.       if ((eh > 0) and (r < eh)) then
  58.         oh := 1
  59.       else
  60.         oh := 0;
  61.       for c := 0 to (columns - 1) do
  62.       begin
  63.         if ((ew > 0) and (c < ew)) then
  64.           ow := 1
  65.         else
  66.           ow := 0;
  67.         i := ((r * columns) + c);
  68.         Result[i].X1 := x;
  69.         Result[i].X2 := (x + (w - 1) + ow);
  70.         Result[i].Y1 := y;
  71.         Result[i].Y2 := (y + (h - 1) + oh);
  72.         x := (Result[i].X2 + 1);
  73.       end;
  74.       y := (Result[i].Y2 + 1);
  75.     end;
  76.   end else
  77.     SetLength(Result, 0);
  78. end;
  79.  
  80. var
  81.   b: TBoxArray;
  82.   h, i, bmp: integer;
  83.   p, e: TPointArray;
  84.  
  85. begin
  86.   bmp := CreateBitmap(BITMAP_WIDTH, BITMAP_HEIGHT);
  87.   DisplayDebugImgWindow(BITMAP_WIDTH, BITMAP_HEIGHT);
  88.   DrawBitmapDebugImg(bmp);
  89.   b := ExplodeBox(IntToBox(MAIN_BOX_X1, MAIN_BOX_Y1, MAIN_BOX_X2, MAIN_BOX_Y2), EXPLOSION_ROWS, EXPLOSION_COLUMNS);
  90.   h := High(b);
  91.   for i := 0 to h do
  92.   begin
  93.     p := TPAFromBox(b[i]);
  94.     FindTPAEdgesWrap(p, e);
  95.     SetPixels(bmp, e, 255);
  96.     SetLength(e, 0);
  97.   end;
  98.   DrawBitmapDebugImg(bmp);
  99. end.
Advertisement
Add Comment
Please, Sign In to add comment