home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PASTUT34 / GRAPHICS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-14  |  2KB  |  62 lines

  1. program parabola_print;
  2.  
  3. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  4. { This program illustrates the graphics capabilities of Turbo Pascal, by }
  5. { using the Line procedure with a suitable algorithm to draw a parabola. }
  6. { Apart from using the Graph unit of Turbo Pascal, a GraphPRN unit is    }
  7. { employed to allow hardcopy to an Epson printer. This latter unit is    }
  8. { listed by Ohlsen and Stoker in 'Turbo Pascal Advanced Techniques'      }
  9. { published by the Que Corporation.                                      }
  10. {                                                                        }
  11. { GRAPHICS.PAS  ->  .EXE    R Shaw             12.1.90                   }
  12. {________________________________________________________________________}
  13.  
  14. uses  Crt,Graph,GraphPRN;
  15.  
  16. var
  17.    GraphDriver,GraphMode      : integer;
  18.    MaxX,MaxY,CopyPRN,OX       : integer;
  19.    PixelX1,PixelY1,PixelY2    : longint;
  20.    x,dx                       : real;
  21.  
  22. { Main program }
  23.  
  24. begin
  25.      TextMode(2);
  26.      Write('If hardcopy is required enter 1 else 0:  ');
  27.      Readln(CopyPRN);
  28.      GraphDriver:=Detect;
  29.      InitGraph(GraphDriver,GraphMode,'');
  30.      MaxX:=GetMaxX;
  31.      MaxY:=GetMaxY;
  32.      SetViewPort(0,0,MaxX,MaxY,ClipOff);
  33.  
  34.      OX := round(MaxX/2);
  35.  
  36.      Line(70,MaxY-40,MaxX-70,MaxY-40);
  37.      Line(OX,40,OX,MaxY-40);
  38.  
  39.      x := -5;
  40.      dx := 10/(maxX-140);
  41.  
  42.      repeat
  43.         pixelX1 := round(MaxX/2 + ((MaxX-140)/10) * x);
  44.         pixelY1 := round(MaxY-40 - ((MaxY-80)/30) * ((x * x) + 5));
  45.         pixelY2 := round(MaxY-40 -((MaxY-80)/30)*((x + dx)*(x + dx) +5));
  46.  
  47.         Line(pixelX1,pixelY1,pixelX1 + 1,pixelY2);
  48.  
  49.         x := x + dx;
  50.  
  51.      until x > 5;
  52.  
  53.      SetTextJustify(CenterText, CenterText);
  54.      OutTextXY(OX,10,'Graph of y = x^2 + 5');
  55.      OutTextXY(OX,MaxY-10,'Press any key to continue');
  56.      If CopyPRN = 1 Then HardCopy(4);
  57.  
  58.      repeat until keypressed;
  59.  
  60.      CloseGraph;
  61.      TextMode(3);
  62. end.