Advertisement
Janilabo

diag

Nov 21st, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.89 KB | None | 0 0
  1. {$loadlib pumbaa.dll}
  2.  
  3. procedure DebugBitmap(bmp: Integer);
  4. var
  5.   w, h: Integer;
  6. begin
  7.   GetBitmapSize(bmp, w, h);
  8.   DisplayDebugImgWindow(w, h);
  9.   DrawBitmapDebugImg(bmp);
  10. end;
  11.  
  12. function TPADiagonals2(bx: TBox): TPointArray;
  13. var
  14.   x, y, z, l, r, w, h, e, o: Integer;
  15.   c: TPoint;
  16. begin
  17.   l := pp_BoxSize(bx);
  18.   SetLength(Result, l);
  19.   if (l > 0) then
  20.   begin
  21.     pp_BoxDimensions(bx, w, h);
  22.     z := ((bx.X1 + h) - 1);
  23.     c := Point(bx.X1, bx.Y1);
  24.     e := 0;
  25.     o := 0;
  26.     repeat
  27.       if (c.X > z) then
  28.         e := (c.X - z);
  29.       if (c.X > bx.X2) then
  30.         o := (c.X - bx.X2);
  31.       y := (bx.Y1 + o);
  32.       for x := (c.X - o) downto (bx.X1 + e) do
  33.       begin
  34.         Result[r] := Point(x, y);
  35.         if (y < bx.Y2) then
  36.           y := (y + 1);
  37.         r := (r + 1);
  38.       end;
  39.       c.X := (c.X + 1);
  40.     until (c.X > (bx.X2 + h));
  41.   end;
  42. end;
  43.  
  44. function TPADiagonals(bx: TBox): TPointArray;
  45. var
  46.   x, y, z, l, r, w, h, e, o: Integer;
  47.   c: TPoint;
  48. begin
  49.   l := pp_BoxSize(bx);
  50.   SetLength(Result, l);
  51.   if (l > 0) then
  52.   begin
  53.     pp_BoxDimensions(bx, w, h);
  54.     z := ((bx.X1 + h) - 1);
  55.     c := Point(bx.X1, bx.Y1);
  56.     e := 0;
  57.     o := 0;
  58.     repeat
  59.       if (c.X > z) then
  60.         e := (c.X - z);
  61.       if (c.X > bx.X2) then
  62.         o := (c.X - bx.X2);
  63.       y := (bx.Y2 - o);
  64.       for x := (c.X - o) downto (bx.X1 + e) do
  65.       begin
  66.         Result[r] := Point(x, y);
  67.         if (y > bx.Y1) then
  68.           y := (y - 1);
  69.         r := (r + 1);
  70.       end;
  71.       c.X := (c.X + 1);
  72.     until (c.X > (bx.X2 + h));
  73.   end;
  74. end;
  75.  
  76. var
  77.   bmp, w, h, i: Integer;
  78.   TPA: TPointArray;
  79.   bx: TBox;
  80.  
  81. begin
  82.   bx := IntToBox(0, 0, 50, 99);
  83.   pp_BoxDimensions(bx, w, h);
  84.   bmp := CreateBitmap(w, h);
  85.   TPA := TPADiagonals2(bx);
  86.   for i := 0 to High(TPA) do
  87.   begin
  88.     FastSetPixel(bmp, TPA[i].X, TPA[i].Y, 255);
  89.     DebugBitmap(bmp);
  90.   end;
  91. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement