home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / sampler / 03 / bezier / curve.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-10-29  |  1.6 KB  |  65 lines

  1. Program curve;
  2.  
  3.    { Draw a Bezier curve on the CGA }
  4.  
  5. USES graph, Bezier, crt;
  6.  
  7. CONST  lastPoint = 6;     { highest subscript used }
  8.  
  9. VAR  pt                                   : vectorArray;
  10.      graphDriver, graphMode, errorCode, n : INTEGER;
  11.      wait                                 : CHAR;
  12. { --------------------------- }
  13.  
  14. PROCEDURE initPoints;     { Define control points }
  15.  
  16. VAR    n, j : INTEGER;
  17.  
  18. BEGIN
  19.   FOR n := 0 TO maxPoints DO     { Zero the array }
  20.     FOR j := 0 TO 2 DO
  21.       pt [n, j] := 0;
  22.   pt [0, 0] := 160;   pt [0, 1] := 110;
  23.   pt [1, 0] := 160;   pt [1, 1] := 160;
  24.   pt [2, 0] :=  55;   pt [2, 1] := 160;
  25.   pt [3, 0] :=  55;   pt [3, 1] :=  20;
  26.   pt [4, 0] := 205;   pt [4, 1] :=  40;
  27.   pt [5, 0] := 190;   pt [5, 1] := 110;
  28.   pt [6, 0] := 280;   pt [6, 1] := 110;
  29. END;
  30. { --------------------------- }
  31.  
  32. BEGIN
  33. { Set up the screen in CGA 320 x 200 mode, palette 1 }
  34.   GraphDriver := CGA;
  35.   GraphMode   := CGAC1;
  36.   InitGraph (graphDriver, graphMode, 'C:\DRIVERS');
  37.  
  38. { Check to make sure it happened }
  39.   ErrorCode := graphResult;
  40.   IF errorCode <> grOK THEN BEGIN
  41.     WRITELN ('Graphics error ', errorCode);
  42.     WRITELN ('Program cannot run');
  43.     HALT (1);
  44.   END;
  45.  
  46. { Draw the hull outline }
  47.   InitPoints;      { First initialize control points }
  48.   SetLineStyle (dottedLn, 0, normWidth);
  49.   SetColor (1);
  50.   MoveTo (pt [0, 0], pt [0, 1]);
  51.   FOR n := 1 TO lastPoint DO
  52.     LineTo (pt [n, 0], pt [n, 1]);
  53.  
  54. { Now draw the curve itself }
  55.   SetLineStyle (solidLn, 0, normWidth);
  56.   SetColor (2);
  57.   DrawBezier2D (pt, lastPoint);
  58.  
  59. { Clean up after a keypress }
  60.   Wait := readkey;
  61.   CloseGraph;
  62. END.
  63.  
  64.  
  65.