
{ get hold of the graphics hardware, draw some stuff to try it out }

program testGraphics;
uses Crt, Graph;

    { find out what kind of video hardware the system has
      and reserve some memory for use as a video buffer }
    procedure openGraph;
    var 
          Gd, Gm: Integer;
    begin
          Gd := Detect;
          { third parameter is path to directory where graphics
            drivers can be found, if not current directory }
          InitGraph(Gd, Gm, '');
          if GraphResult <> grOk then
          begin
               writeln('You did not Enable Turbo Graphics.');
               write('Press ENTER to exit.'); readln;
               Halt(1);
          end;
    end;

var
   maxX,maxY,maxC,r: integer;

begin
     { get in touch with the video hardware }
     openGraph;

{ --------------------------------------------------------------- }
{ STUDENTS: Copy down to here, then use line( ) and (optionally)
  other graphics procedures to draw a picture.  You can search for
  the other graphics procedures under the Help menu.              }

     { find out how big the screen is, how many colors available }
     maxX := getMaxX; maxY := getMaxY; maxC := getMaxColor;

     { top-left of screen is (0,0); lower right is (maxX,maxY);
       on lab PC's, maxX is about 640, maxY is about 480         }

     { draw some lines on the screen }
     line(130,300, 130,280);   { a short vertical }
     line(100,280, 130,200);   { a short diagonal up }
     line(130,200, 160,280);   { a short diagonal down }
     line(0,300, maxX,300);    { a long horizontal }

     { draw expanding circles centered on pixel 200,200 }
     for r := 1 to 5 do
     begin
         setColor((r mod maxC)+1); { use mod so 0 < r <= maxC }
         circle(400,150, 25*r);    { x,y of center, radius }
     end;

     { write some text on the screen }
     setColor(maxC);
     outTextXY(400,150,'Merry Christmas!');

     { fill screen with dots while waiting for user to press key }
     randomize;
     while not keyPressed do
        putPixel(random(maxX),random(300),random(maxC));

{ --------------------------------------------------------------- }
{ STUDENTS: Include closeGraph at the end of your program.        }

     { restore screen to previous state and release some memory }
     closeGraph;
end.


