home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1987 / 01 / draw.inc < prev    next >
Encoding:
Text File  |  1986-11-25  |  4.2 KB  |  144 lines

  1. (*****************************************************************************)
  2. (*                                                                           *)
  3. (*                         ---  DRAW.INC  ---                                *)
  4. (*                                                                           *)
  5. (*               Unterprogramm-Modul zum Zeichnen der Funktion               *)
  6. (*                                                                           *)
  7. (*****************************************************************************)
  8.  
  9.  
  10. Procedure PlotFunction;
  11.  
  12.  
  13.    Var xmin,xmax,
  14.        ymin,ymax,
  15.        dx,dy,x,d  :Real;
  16.        s          :Integer;
  17.  
  18.  
  19.    (* Hier beginnt der hardwareabhaengige Teil *)
  20.  
  21.    Const ScreenXMax = MaxInt; (* Anzahl Bildpunkte horizontal                 *)
  22.          ScreenYMax = MaxInt; (*                   vertikal                   *)
  23.          Left       = 500;    (* Abstand Zeichenflaeche-linker Bildschirmrand *)
  24.          Bottom     = 500;    (*                       -unterer               *)
  25.          Unit       = 200;   (* halbe Breite der Achsenunterteilungsstriche  *)
  26.  
  27.  
  28.    Procedure InitGraphic;     (* Voreinstellungen fuer Grafikbetrieb *)
  29.  
  30.       Begin
  31.         Open_Workstation(Screen);
  32.         IF VDI_Error THEN Halt;
  33.         Enter_Graphics;
  34.       End;
  35.  
  36.  
  37.    Procedure LeaveGraphic;    (* Voreinstellungen fuer Textbetrieb *)
  38.  
  39.       Begin
  40.         Close_Workstation;
  41.       End;
  42.  
  43.  
  44.    Procedure Plot (x,y :Integer);    (* Punkt bei (x,y) zeichnen *)
  45.  
  46.        Begin
  47.          ptsin[1] := x;  ptsin[2] := y;  ptsin[3] := x; ptsin[4] := y;
  48.          Poly_Line(2, ptsin);
  49.        End;
  50.  
  51.  
  52.    Procedure Draw (x1,y1,x2,y2 :Integer);  (* Linie von (x1,y1) nach (x2,y2) *)
  53.  
  54.       Begin
  55.          ptsin[1] := x1;  ptsin[2] := y1;  ptsin[3] := x2;  ptsin[4] := y2;
  56.          Poly_Line(2, ptsin);
  57.       End;
  58.  
  59.    (* hier endet der hardwareabhaengige Teil *)
  60.  
  61.  
  62.    Procedure WorldToScreen (x,y :Real; Var xs,ys :Integer);
  63.  
  64.       Begin
  65.       xs := round((x - xmin)*(ScreenXMax-Left)/(xmax-xmin)) + Left;
  66.       ys := round((y - ymin)*(ScreenYMax-Bottom)/(ymax-ymin)) + Bottom
  67.       End;
  68.  
  69.  
  70.    Procedure DrawPoint (x,y :Real);    (* zeichnet Punkt in Weltkoordinaten *)
  71.  
  72.       Var xp,yp :Integer;
  73.  
  74.       Begin
  75.       WorldToScreen (x,y,xp,yp);
  76.       Plot (xp,yp)
  77.       End;
  78.  
  79.  
  80.    Procedure DrawLine (x1,y1,x2,y2 :Real); (* zeichnet Linie in Weltkoordinaten *)
  81.  
  82.       Var xp1,yp1,xp2,yp2 :Integer;
  83.  
  84.       Begin
  85.       WorldToScreen (x1,y1,xp1,yp1);
  86.       WorldToScreen (x2,y2,xp2,yp2);
  87.       Draw (xp1,yp1,xp2,yp2)
  88.       End;
  89.  
  90.  
  91.    Procedure DrawAxis;   (* zeichnet das Achsenkreuz *)
  92.  
  93.       Var x,y,Dist :Real;
  94.  
  95.       Begin
  96.       Draw (Left,Bottom,Left,ScreenYMax);
  97.       Draw (Left,Bottom,ScreenXMax,Bottom);
  98.       DrawLine (xmin,0,xmax,0);
  99.       DrawLine (0,ymin,0,ymax);
  100.  
  101.       dist := dy*(ScreenYMax-Bottom)/(ymax-ymin); (* Abstand y-Unterteilung *)
  102.       x := Left;
  103.       y := Bottom;
  104.       While y<=ScreenYMax do
  105.          Begin
  106.          Draw (round(x-Unit),round(y),round(x+Unit),round(y));
  107.          y := y + Dist
  108.          End;
  109.  
  110.       dist := dx*(ScreenXMax-Left)/(xmax-xmin);   (* Abstand y-Unterteilung *)
  111.       x := Left;
  112.       y := Bottom;
  113.       While x<=ScreenXMax do
  114.          Begin
  115.          Draw (round(x),round(y-Unit),round(x),round(y+Unit));
  116.          x := x + Dist
  117.          End;
  118.       End;
  119.  
  120.  
  121.    Begin
  122.    ClrScr;
  123.    WriteLn ('Funktion zeichnen'); WriteLn;
  124.    Write ('im Bereich von xmin='); Read (xmin);
  125.    Write (' bis xmax='); Read (xmax);
  126.    Write (' mit Schrittweite dx='); ReadLn (dx); WriteLn;
  127.    Write ('           von ymin='); Read (ymin);
  128.    Write (' bis ymax='); Read (ymax);
  129.    Write (' mit Schrittweite dy='); ReadLn (dy); WriteLn;
  130.    Write ('Anzahl der zu berechnenden Stuetzstellen: '); ReadLn (s);
  131.  
  132.    InitGraphic;                               (* Grafik initialisieren *)
  133.    DrawAxis;                                  (* Achsenkreuz zeichnen  *)
  134.    x := xmin;
  135.    d := (xmax-xmin)/s;
  136.    While x+d<=xmax do
  137.       Begin
  138.       DrawLine (x,fn(x,0),x+d,fn(x+d,0));     (* Zeichnen der Funktion *)
  139.       x := x + d
  140.       End;
  141.    Repeat until KeyPressed;
  142.    LeaveGraphic
  143.    End;
  144.