home *** CD-ROM | disk | FTP | other *** search
/ Vectronix 2 / VECTRONIX2.iso / FILES_01 / HISPEED2.LZH / GEMDEMO / DEMOGRAP.PAS < prev    next >
Pascal/Delphi Source File  |  1991-07-02  |  5KB  |  159 lines

  1. {---------------------------------------------------------------------
  2.               Graphic demo procedures for GEMDEMO
  3.  
  4.                 Copyright (c) 1990 D-House I ApS
  5.                        All rights reserved
  6.  
  7.                  Programmed by Martin Eskildsen
  8. ---------------------------------------------------------------------}
  9.  
  10. {$D+}
  11. unit DemoGraphs;
  12.  
  13. INTERFACE
  14.  
  15. uses GemDecl, GemAES, GemVDI, DemoInterface;
  16.  
  17. { Set up a local array of coordinates, fill styles etc. used for
  18.   speedy graphics window update }
  19. procedure MakeGraphData;
  20.  
  21. { Make sure the entire graphics window is redrawn. This is required
  22.   when the user selected demo type }
  23. procedure ForceGraphicsRedraw;
  24.  
  25. { Do BOXES demo }
  26. procedure DoBoxes;
  27.  
  28. { Do LINES demo }
  29. procedure DoLines;
  30.  
  31. { Do ELLIPSES demo }
  32. procedure DoEllipses;
  33.  
  34. { Do PIES demo }
  35. procedure DoPies;
  36.  
  37. {$F+,D-,R-,S-}   { <--- note this if you are experimenting }
  38.  
  39. IMPLEMENTATION
  40.  
  41. const
  42.   DataSize       = 80;    { size of graphics data array }
  43.  
  44. var
  45.   wX, wY, wW, wH : Integer;   { Size of graphics window work area }
  46.   GraphData      : array [1..DataSize] of record  { the array : }
  47.                      x, y,
  48.                      x_rad, y_rad,              { radius x and y      }
  49.                      beg_ang, end_ang,          { start and end angle }
  50.                      fill_style, fill_index : Integer
  51.                    end;
  52.  
  53. procedure MakeGraphData;
  54. var i : integer;
  55. begin
  56.   Randomize;
  57.   for i := 1 to DataSize do with GraphData[i] do begin
  58.     x          := Random(MinX + MaxW - 1);
  59.     y          := Random(MinY + MaxH - 1);
  60.     x_rad      := Random(MaxW DIV 5);
  61.     y_rad      := Random(MaxH DIV 5);
  62.     beg_ang    := Random(3600);        { GEM uses 1/10 degrees }
  63.     end_ang    := Random(3600);
  64.     fill_style := Random(1) + 2;
  65.     fill_index := Random(12) + 1
  66.   end
  67. end;
  68.  
  69. { Return current size of the graphics window work area }
  70. procedure GetWindowSize;
  71. begin
  72.   wind_get(grafwindow, WF_WORKXYWH, wX, wY, wW, wH)
  73. end;
  74.  
  75. { This is advanced! The trick is, however, quite simple : Let the
  76.   procedure put a message into the event pipe saying that a redraw
  77.   is requested. In this way, we let the GEMDEMO application write a
  78.   message to... the GEMDEMO application! }
  79. procedure ForceGraphicsRedraw;
  80. var
  81.   mypipe : array [0..7] of integer;
  82. begin
  83.   GetWindowSize;                { Redraw all of window  }
  84.   mypipe[0] := WM_REDRAW;       { The message           }
  85.   mypipe[3] := grafwindow;      { The window            }
  86.   mypipe[4] := wX;              { x                     }
  87.   mypipe[5] := wY;              { y                     }
  88.   mypipe[6] := wW;              { width                 }
  89.   mypipe[7] := wH;              { height                }
  90.   appl_write(AES_handle, sizeof(mypipe), mypipe)  { write message }
  91. end;
  92.  
  93. { Draw a line from (x,y) to (x1,y1) }
  94. procedure Line(x,y,x1,y1 : Integer);
  95. var p : ptsin_Array;
  96. begin
  97.   p[0] := x;  p[1] := y;  p[2] := x1;  p[3] := y1;
  98.   v_pline(VDI_handle, 2, p)
  99. end;
  100.  
  101. procedure DoBoxes;
  102. var
  103.   i : Integer;   { index }
  104.   a : Array_4;   { coordinates of two diagonally opposite corners }
  105. begin
  106.   GetWindowSize;
  107.   vsf_color(VDI_handle, black);           { fill color is black }
  108.   for i := 1 to DataSize do with GraphData[i] do begin
  109.     vsf_style(VDI_handle, fill_style);    { set fill style }
  110.     vsf_interior(VDI_handle, fill_index); { set fill type  }
  111.     a[0] := x + wX;              a[1] := y + wY;
  112.     a[2] := x + wX + x_rad - 1;  a[3] := y + wY + y_rad - 1;
  113.     v_bar(VDI_handle, a)                  { make the box   }
  114.   end
  115. end;
  116.  
  117. procedure DoLines;
  118. var
  119.   i             : Integer;
  120.   Xstep, Ystep  : Integer;      { step sizes in x and y direction }
  121. begin
  122.   GetWindowSize;                { get window size }
  123.   Xstep := wW div 30;           { step 1/30 of its width in x dir }
  124.   Ystep := wH div 30;           { and 1/30 of its height in y dir }
  125.   for i := 0 to 39 do begin     { draw 40 times                   }
  126.     line(wX, wY + i*Ystep, wX + i*Xstep, wY + wH);
  127.     line(wX + wW, wY + i*Ystep, wX + wW - i*Xstep, wY + wH);
  128.     line(wX, wY + wH - i*Ystep, wX + i*Xstep, wY);
  129.     line(wX + wW, wY + wH - i*Ystep, wX + wW - i*Xstep, wY)
  130.   end
  131. end;
  132.  
  133. procedure DoEllipses;
  134. var i : Integer;
  135. begin
  136.   GetWindowSize;
  137.   vsf_color(VDI_handle, black);                 { fill color : black }
  138.   for i := 1 to DataSize do with GraphData[i] do begin
  139.     vsf_style(VDI_handle, fill_style);          { set fill style     }
  140.     vsf_interior(VDI_handle, fill_index);       { set fill type      }
  141.     v_ellipse(VDI_handle, x + wX, y + wY, x_rad, y_rad)
  142.                                                 { draw the ellipse   }
  143.   end
  144. end;
  145.  
  146. procedure DoPies;
  147. var i : Integer;
  148. begin
  149.   GetWindowSize;
  150.   vsf_color(VDI_handle, black);                 { fill is black  }
  151.   for i := 1 to DataSize do with GraphData[i] do begin
  152.     vsf_style(VDI_handle, fill_style);          { set fill style }
  153.     vsf_interior(VDI_handle, fill_index);       { set fill type  }
  154.     v_ellpie(VDI_handle, x + wX, y + wY, x_rad, y_rad, beg_ang, end_ang)
  155.   end                                           { ^ : draw the pie }
  156. end;
  157.  
  158. end.
  159.