home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TP_ADV.ZIP / LIST1202.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1989-11-17  |  2.2 KB  |  61 lines

  1. Program Servant;
  2.  
  3. Uses
  4.   CRT,
  5.   Graph;
  6.  
  7. Const
  8.   FileName = 'F:\DATA.DAT';
  9.  
  10. Type
  11.   arType = Array [1..5] of Word;
  12.  
  13. Var
  14.   f     : File Of arType;
  15.   a     : arType;
  16.   gd,                                            { For graphics }
  17.   gm    : Integer;                                     { " }
  18.   loop,                              { General purpose variable }
  19.   pieSeg,                    { Used to hold size of pie segment }
  20.   sub,                         { Used to track total angle size }
  21.   total : Word;             { Used to hold the sum of the array }
  22.  
  23. Begin
  24.   gd := Detect;                               { Use Auto detect }
  25.   InitGraph ( gd, gm, '' );           { Initialize the graphics }
  26.   If ( GraphResult <> grOk ) Then
  27.   Begin                               { If graphics error, halt }
  28.     WriteLn ( GraphResult );
  29.     Halt;
  30.   End;
  31.   Assign ( f, FileName );
  32.   FileMode := 64;                { Access Read Only - Deny None }
  33.   Repeat
  34.     {$I-}
  35.     Reset ( f );          { Loop until the file exists, this    }
  36.     loop := IOResult;     { will make Servant wait until Master }
  37.     {$I+}                 { has started running.                }
  38.   Until ( loop = 0 );
  39.   Repeat
  40.     Seek ( f, 0 );                  { Move to start of the file }
  41.     Read ( f, a );                       { Read the information }
  42.  
  43.     sub := 0;                               { Initialize values }
  44.     total := 0;                                     { " }
  45.     For loop := 1 to 5 Do
  46.       total := total + a[loop];               { Calculate total }
  47.     For loop := 1 to 5 Do
  48.     Begin
  49.       SetFillStyle ( SolidFill, loop );    { Set a unique color }
  50.       pieSeg := Round ( ( a[loop] / total ) * 360 );
  51.       If ( pieSeg + sub > 360 ) Then   { Make sure we do not go over }
  52.         pieSeg := 360 - sub;           { 360 degrees.                }
  53.       PieSlice ( GetMaxX div 2, GetMaxY div 2, sub, sub + pieSeg,
  54.                  GetMaxY div 2 - 20 );         { Draw pie slice }
  55.       sub := sub + pieSeg;
  56.     End;
  57.   Until KeyPressed;                        { Stop on user input }
  58.   Close ( f );                                 { Close the file }
  59.   CloseGraph;
  60. End.
  61.