home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 14 / CDACTUAL.iso / cdactual / demobin / share / program / Pascal / TURTLE10.ZIP / TURTLE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-12-14  |  23.6 KB  |  699 lines

  1. {------------------------------------------------------------------------}
  2. { PROJECT   : Turtle graphics using BGI                                  }
  3. { MODULE    : TURTLE.PAS                                                 }
  4. {------------------------------------------------------------------------}
  5. { GOAL      : Source code of the main unit                               }
  6. { VERSION   : 1.1e (e)English comments                                   }
  7. {------------------------------------------------------------------------}
  8. { REVISIONS : added fast trigo calculations                              }
  9. {           : added TurtleBox (Color) for demo purposes                  }
  10. {------------------------------------------------------------------------}
  11. { AUTHOR    : P.Pollet INSA   12/12/92                                   }
  12. {------------------------------------------------------------------------}
  13.  
  14. UNIT TURTLE;
  15.  
  16. {$DEFINE FASTTRIGO}  { set to true for faster Trigonometric calculations}
  17.                      { leave it on . Was used for debugging purposes    }
  18.  
  19. INTERFACE
  20.  
  21. uses Graph,  { for BGI calls }
  22.      Crt;    { just for a call to Delay }
  23.  
  24. const
  25.   { angles in degrees for standard headings }
  26.   North = 0;
  27.   East  = 90;
  28.   South = 180;
  29.   West  = 270;
  30.  
  31.  
  32. procedure GraphOff;
  33.   {Turn off graphic mode }
  34.  
  35. procedure GraphOn(driver,mode:integer;path:string);
  36.  { go to graphic mode specified by Driver,Mode            }
  37.  { works only with Std Borland drivers that can be loaded }
  38.  { via InitGraph and not InstallUserDriver. See examples  }
  39.  { for non standard BGI                                   }
  40. procedure InitTurtle;
  41.  { renitialize the turtle. Internally called by GraphOn.  }
  42.  { MUST BE CALLED with UserInstalled BGI after swapping   }
  43.  { to graph mode.                                         }
  44.  {   Put the turtle center of screen.                     }
  45.  {   Set up  turtle woindow to full screen depending of   }
  46.  {       the maximal allowed pixels coordinates           }
  47.  {   Set Turtle and Standard line colors to white         }
  48.  {   Turtle is initially Hidden,no wrap, no delay         }
  49.  {   Pen is down                                          }
  50.  
  51. procedure ClearScreen;
  52.  { erase all the graphic screen using BGI calls }
  53.  
  54. procedure FillScreen (Color:Byte);
  55.  { fill the turtle Window, not the screen with Color      }
  56.  { to erase to turtle Windows use FillScreen(0)           }
  57.  
  58. procedure Back(Dist: Integer);
  59.  { move the turtle back of Dist pixels                    }
  60.  { to clear the Turtle Window, use FillScreen(0)          }
  61.  
  62. procedure Forwd(Dist: Integer);
  63.  { move the turtle forward of Dist pixels }
  64.  
  65. function  Heading: Integer;
  66.  { return the current Heading within -359 to 359 }
  67.  { 0 = toward North. 90 =East ....               }
  68.  
  69. procedure HideTurtle;
  70.  { hide the turtle }
  71.  
  72. procedure Home;
  73.   { go center of turtle window, Heading=0 North}
  74.  
  75. procedure NoWrap;
  76.   { Do not roll the drawing on the other side of the screen }
  77.   { if the turtle goes offscreen. }
  78.  
  79. procedure PenDown;
  80.    { From now, all moves will leaves a track behind }
  81.  
  82. procedure PenUp;
  83.    { From now, all moves will not leaves a track behind }
  84.  
  85. procedure SetHeading(Angle: Integer);
  86.    { Set the new heading of turtle. Internally adusted within }
  87.    { -359..359 degrees. Redraw the turtle if visible }
  88.  
  89. procedure SetPenColor(Color: Integer);
  90.    { change the color  of the turtle ,of its track              }
  91.    { and the BGI standard color.                                }
  92.    { To draw using BGI in a different color, use Graph.SetColor }
  93.  
  94. procedure SetPosition(X,Y: Integer);
  95.    { place the turtle at position X,Y, relative to the }
  96.    { turtle window origin.(center of the window) }
  97.  
  98. procedure ShowTurtle;
  99.    { show the turtle }
  100.  
  101. procedure TurnLeft(Angle: Integer);
  102.    { add Angle to the heading. redraw if visible }
  103.  
  104. procedure TurnRight(Angle: Integer);
  105.    { subtract Angle from heading. redraw if visible }
  106.  
  107. procedure TurtleDelay(Delay: integer);
  108.    { Set delay time in Milliseconds between every move }
  109.  
  110. procedure TurtleWindow(X,Y,W,H: Integer);
  111.    { define the screen area where the turtle is clipped }
  112.    { X,Y are TopLerft corner coordinates. W is horizontal Width }
  113.    { H is vertical Height }
  114.  
  115. function  TurtleThere: Boolean;
  116.    { Return true if Turtle is visible *AND* within Turtle window}
  117.  
  118. procedure Wrap;
  119.   { Do roll the drawing on the other side of the screen }
  120.   { if the turtle goes offscreen. }
  121.  
  122. function  Xcor: Integer;
  123.   { return current X position in Turtle coordinates}
  124.  
  125. function  Ycor: Integer;
  126.   { return current Y position in Turtle coordinates}
  127.  
  128.  
  129. procedure TurtleBox (aColor:Byte);
  130.   { draw a box in Color round the current turtle window}
  131.  
  132. {----------------------------------------------- REDEF GRAPH  }
  133. { to allow the use of standard graph routines,with the turtle }
  134. { graphics, it is capital to HIDE the turtle before any access}
  135. { to screen and to show it afterwards. Otherwise the XOR mode }
  136. { used to animate the turtle will not work properly if a non  }
  137. { turtle line has crossed the turtle image ...                }
  138. {-------------------------------------------------------------}
  139. { we have simply redefined here the BGI calls that access the }
  140. { screen to hide the turtle during calls to the original      }
  141. { routines..                                                  }
  142. {-------------------------------------------------------------}
  143. { ********** WARNING WARNING WARNING WARNING WARNING *********}
  144. { this works only if you include the TURTLE unit AFTER the    }
  145. { GRAPH unit in any USES clause                               }
  146. {-------------------------------------------------------------}
  147.  
  148. { *** Screen, viewport, page routines *** }
  149. procedure ClearDevice;
  150. procedure ClearViewPort;
  151.  
  152. { *** point-oriented routines *** }
  153. procedure PutPixel(X, Y : integer; Pixel : word);
  154. function  GetPixel(X, Y : integer) : word;
  155.  
  156. { *** line-oriented routines *** }
  157. procedure LineTo(X, Y : integer);
  158. procedure LineRel(Dx, Dy : integer);
  159. procedure MoveTo(X, Y : integer);
  160. procedure MoveRel(Dx, Dy : integer);
  161. procedure Line(x1, y1, x2, y2 : integer);
  162.  
  163. { *** polygon, fills and figures *** }
  164. procedure Rectangle(x1, y1, x2, y2 : integer);
  165. procedure Bar(x1, y1, x2, y2 : integer);
  166. procedure Bar3D(x1, y1, x2, y2 : integer; Depth : word; Top : boolean);
  167. procedure DrawPoly(NumPoints : word; var PolyPoints);
  168. procedure FillPoly(NumPoints : word; var PolyPoints);
  169. procedure FloodFill(X, Y : integer; Border : word);
  170.  
  171. { *** arc, circle, and other curves *** }
  172. procedure Arc(X, Y : integer; StAngle, EndAngle, Radius : word);
  173. procedure Circle(X, Y : integer; Radius : word);
  174. procedure Ellipse(X, Y : integer;
  175.                   StAngle, EndAngle : word;
  176.                   XRadius, YRadius  : word);
  177. procedure FillEllipse(X, Y : integer;
  178.                       XRadius, YRadius  : word);
  179. procedure PieSlice(X, Y : integer; StAngle, EndAngle, Radius : word);
  180. procedure Sector(X, Y : Integer;
  181.                  StAngle, EndAngle,
  182.                  XRadius, YRadius : word);
  183.  
  184.  
  185. { *** bit-image routines *** }
  186. procedure GetImage(x1, y1, x2, y2 : integer; var BitMap);
  187. procedure PutImage(X, Y : integer; var BitMap; BitBlt : word);
  188.  
  189. { *** text routines *** }
  190. procedure OutText(TextString : string);
  191. procedure OutTextXY(X, Y : integer; TextString : string);
  192.  
  193. {------------------------------------------------------------------}
  194. { In future versions of BGI drivers, add here new screen accessing }
  195. { calls to be trapped .                                            }
  196. {------------------------------------------------------------------}
  197.  
  198. IMPLEMENTATION
  199.  
  200. {----------------------------------------------------------------------}
  201. { PRIVATE PART OF THE UNITS. NONE OF THE CALLS BELOW ARE VISIBLE IN    }
  202. { THE INTERFACE.                                                       }
  203. {----------------------------------------------------------------------}
  204.  
  205. var G_maxX,              { storage of Graph.GetMaxX.   set in InitTurtle }
  206.     G_MaxY,              { storage of Graph.GetMaxY.   set in InitTurtle }
  207.     G_MaxColor:integer;  { storage of Graph.GetMaxColor set in InitTurtle }
  208.  
  209.     T_Wrap     :Boolean; { flag to indicate whether we wrap or not}
  210.     T_PenDown  :Boolean; { flag to indicate whether we draw or Move}
  211.     T_Visible  :Boolean; { flag to indicate whether the Turtle is visible}
  212.     T_PenColor :Byte;    { current Pen Color = Value AND G_maxColor  }
  213.     T_Delay    :Integer; { delay in Ms after every move }
  214.     T_Heading  :Integer; { current heading 0=North. }
  215.     T_PosX,              { current Turtle position X,Y }
  216.     T_PosY     :Integer; { in TURTLE Coordinates  }
  217.     T_WinLoX,            { Bottom Left on Turtle Window }
  218.     T_WinLoY,            {   in SCREEN coordinates      }
  219.     T_WinHiX,            { Top Right of Turtle Window   }
  220.     T_WinHiY   :Integer; {   in SCREEN coordinates      }
  221.     T_WinOrgX,           { origin of the Turtle Window  }
  222.     T_WinOrgY   :Integer;{   in SCREEN coordinates      }
  223.  
  224.  
  225. {$IFDEF  FASTTRIGO}
  226.  
  227. { table of 10000*sine of angles from 0 to 359 }
  228.  
  229. const Sinus:array[0..359] of Integer=(
  230.      0,   175,   349,   523,   698,   872,  1045,  1219,  1392,  1564,
  231.   1736,  1908,  2079,  2250,  2419,  2588,  2756,  2924,  3090,  3256,
  232.   3420,  3584,  3746,  3907,  4067,  4226,  4384,  4540,  4695,  4848,
  233.   5000,  5150,  5299,  5446,  5592,  5736,  5878,  6018,  6157,  6293,
  234.   6428,  6561,  6691,  6820,  6947,  7071,  7193,  7314,  7431,  7547,
  235.   7660,  7771,  7880,  7986,  8090,  8192,  8290,  8387,  8480,  8572,
  236.   8660,  8746,  8829,  8910,  8988,  9063,  9135,  9205,  9272,  9336,
  237.   9397,  9455,  9511,  9563,  9613,  9659,  9703,  9744,  9781,  9816,
  238.   9848,  9877,  9903,  9925,  9945,  9962,  9976,  9986,  9994,  9998,
  239.  10000,  9998,  9994,  9986,  9976,  9962,  9945,  9925,  9903,  9877,
  240.   9848,  9816,  9781,  9744,  9703,  9659,  9613,  9563,  9511,  9455,
  241.   9397,  9336,  9272,  9205,  9135,  9063,  8988,  8910,  8829,  8746,
  242.   8660,  8572,  8480,  8387,  8290,  8192,  8090,  7986,  7880,  7771,
  243.   7660,  7547,  7431,  7314,  7193,  7071,  6947,  6820,  6691,  6561,
  244.   6428,  6293,  6157,  6018,  5878,  5736,  5592,  5446,  5299,  5150,
  245.   5000,  4848,  4695,  4540,  4384,  4226,  4067,  3907,  3746,  3584,
  246.   3420,  3256,  3090,  2924,  2756,  2588,  2419,  2250,  2079,  1908,
  247.   1736,  1564,  1392,  1219,  1045,   872,   698,   523,   349,   175,
  248.      0,  -175,  -349,  -523,  -698,  -872, -1045, -1219, -1392, -1564,
  249.  -1736, -1908, -2079, -2250, -2419, -2588, -2756, -2924, -3090, -3256,
  250.  -3420, -3584, -3746, -3907, -4067, -4226, -4384, -4540, -4695, -4848,
  251.  -5000, -5150, -5299, -5446, -5592, -5736, -5878, -6018, -6157, -6293,
  252.  -6428, -6561, -6691, -6820, -6947, -7071, -7193, -7314, -7431, -7547,
  253.  -7660, -7771, -7880, -7986, -8090, -8192, -8290, -8387, -8480, -8572,
  254.  -8660, -8746, -8829, -8910, -8988, -9063, -9135, -9205, -9272, -9336,
  255.  -9397, -9455, -9511, -9563, -9613, -9659, -9703, -9744, -9781, -9816,
  256.  -9848, -9877, -9903, -9925, -9945, -9962, -9976, -9986, -9994, -9998,
  257. -10000, -9998, -9994, -9986, -9976, -9962, -9945, -9925, -9903, -9877,
  258.  -9848, -9816, -9781, -9744, -9703, -9659, -9613, -9563, -9511, -9455,
  259.  -9397, -9336, -9272, -9205, -9135, -9063, -8988, -8910, -8829, -8746,
  260.  -8660, -8572, -8480, -8387, -8290, -8192, -8090, -7986, -7880, -7771,
  261.  -7660, -7547, -7431, -7314, -7193, -7071, -6947, -6820, -6691, -6561,
  262.  -6428, -6293, -6157, -6018, -5878, -5736, -5592, -5446, -5299, -5150,
  263.  -5000, -4848, -4695, -4540, -4384, -4226, -4067, -3907, -3746, -3584,
  264.  -3420, -3256, -3090, -2924, -2756, -2588, -2419, -2250, -2079, -1908,
  265.  -1736, -1564, -1392, -1219, -1045,  -872,  -698,  -523,  -349,  -175);
  266.  
  267.  
  268. Function FastSin (A:integer):LongInt;
  269. { fast table look Sinus*10000 in LongInt    }
  270. { Requires the Mod 360 for Runtime error in }
  271. { drawing the turtle with Heading < -240    }
  272. begin
  273.  If A>=0 then FastSin:=Sinus[A mod 360]
  274.  else FastSin:=-Sinus[-A mod 360];
  275. end;
  276.  
  277. Function FastCos (A:integer):LongInt;
  278. { nothing really great here....             }
  279. begin
  280.   FastCos:=FastSin(A+90)
  281. end;
  282.  
  283. {$ELSE}
  284.    { the formulae we used to build the Table above }
  285.    Function FastSin(A:Integer):LongInt;
  286.    begin
  287.       FastSin:=Round(sin(A*pi/180)*10000);
  288.    end;
  289.  
  290.    Function FastCos(A:Integer):LongInt;
  291.    begin
  292.      FastCos:=Round(Cos(A*pi/180)*10000);
  293.    end;
  294.  
  295. {$ENDIF}
  296.  
  297. {--------------------------------------------------------}
  298. { Conversion of Turtle Coordinates to Screen coordinates }
  299. {--------------------------------------------------------}
  300. Function ToScreenX (Xt:Integer):Integer;
  301. begin
  302.   ToScreenX:=T_WinOrgX +Xt
  303. end;
  304.  
  305. Function ToScreenY (Yt:Integer):Integer;
  306. { Turtle Y axis goes up, and Screen y axis goes down }
  307. begin
  308.   ToScreenY:=T_WinOrgY -Yt
  309. end;
  310.  
  311. {--------------------------------------------------------}
  312. { Reset the Turtle to standard settings.....             }
  313. { Reset all but the turtle window                        }
  314. {--------------------------------------------------------}
  315. Procedure ResetTurtle;
  316. begin
  317.   T_PenColor:=WHITE and G_MaxColor;
  318.   SetColor(T_PenColor);
  319.   T_Wrap:=false;
  320.   T_PenDown:=True;
  321.   T_Visible:=false;
  322.   T_Delay:=0;
  323.   Home;
  324. end;
  325.  
  326. {--------------------------------------------------------}
  327. { Draw the Turtle as a triangle in XOR mode              }
  328. { may be modified to change Turtle aspect                }
  329. {--------------------------------------------------------}
  330. Procedure DrawTurtle(OnOff:Boolean);
  331. var Sc:Integer;
  332.  
  333.     procedure DrawTriangle (Xc,Yc,Angle:Integer);
  334.     Const L=15;
  335.     var Xt,Yt,X,Y:integer;
  336.     begin
  337.       Xt:=Xc+ (LongInt(L)*FastCos(Angle) div 10000);
  338.       Yt:=Yc+ (LongInt(L)*FastSin(Angle) div 10000);
  339.       Xt:=ToScreenX(Xt);
  340.       Yt:=ToScreenY(Yt);
  341.       { Watch out for infinite loops if Graph. is omitted   }
  342.       { MoveTo of the unit is redefined to call _HideTurtle }
  343.       { that will call DrawTurtle(false)......              }
  344.       Graph.MoveTo(Xt,Yt);
  345.       X:=Xc+ (LongInt(L)*FastCos(Angle+120) div 10000);
  346.       Y:=Yc+ (LongInt(L)*FastSin(Angle+120) div 10000);
  347.       Graph.LineTo(ToScreenX(X),ToScreenY(Y));
  348.       Graph.LineTo(ToScreenX(Xc),ToScreenY(Yc));
  349.       X:=Xc+ (LongInt(L)*FastCos(Angle-120) div 10000);
  350.       Y:=Yc+ (LongInt(L)*FastSin(Angle-120) div 10000);
  351.       Graph.LineTo(ToScreenX(X),ToScreenY(Y));
  352.       Graph.LineTo(Xt,Yt);
  353.       Graph.MoveTo(ToScreenX(Xc),ToScreenY(Yc));
  354.     end;
  355.  
  356. begin
  357.   SetWriteMode(XorPut);
  358.   DrawTriangle(T_PosX,T_PosY,90-T_Heading);
  359.   SetWriteMode(CopyPut);
  360. end;
  361.  
  362. {--------------- helper procedures to save some time------------}
  363.  
  364. { Hide the Turtle if not visible. Called by the redefined BGI calls}
  365. { and the public HideTurtle.. DO Not Modify the flag T_Visible     }
  366. Procedure _HideTurtle;
  367. begin
  368.   if T_Visible then DrawTurtle(False)
  369. end;
  370.  
  371. Procedure _ShowTurtle;
  372. begin
  373.   if T_Visible then DrawTurtle(True)
  374. end;
  375.  
  376. { Redraw the turtle if visible called at the end of all Turtle drawing }
  377. { procedures. Waste some time if Turtel Delay is set                   }
  378. Procedure _ShowTurtleDelay;
  379. begin
  380.   if T_Visible then
  381.     begin
  382.       DrawTurtle(True);
  383.       if T_Delay >0 then Delay(T_Delay)
  384.    end
  385. end;
  386.  
  387. { return true in the point X,Y is within the rectangle      }
  388. { defined by X1,Y1 and Y1,Y2 .regardless of the coordinates }
  389. { system (SCREEN or TURTLE )                                }
  390. Function PtInRect(X,Y,X1,Y1,X2,Y2:Integer):Boolean;
  391. begin
  392.   PtInRect:=(X>=X1) and (X<=X2) and (Y>=Y1) and (Y <=Y2)
  393. end;
  394.  
  395.  
  396. {----------------------------------------------------------------------}
  397. { END OF PRIVATE PART..................................................}
  398. {----------------------------------------------------------------------}
  399.  
  400.  
  401.  
  402. {----------------------------------------------------------------------}
  403. { CODE OF THE PUBLIC PROCEDURES AND FUNCTIONS OF THIS UNIT             }
  404. {----------------------------------------------------------------------}
  405.  
  406.  
  407. procedure GraphOff;
  408. begin
  409.   CloseGraph;
  410. end;
  411.  
  412. procedure GraphOn(driver,mode:integer;path:string);
  413. var ErrorCode:Integer;
  414. const EGApalette :PaletteType=
  415.   (size:16;
  416.    colors:
  417.     (EGABLACK,EGABLUE,EGAGREEN,EGACYAN,EGARED,EGAMAGENTA,EGABROWN,
  418.     EGALIGHTGRAY,EGADARKGRAY,EGALIGHTBLUE,EGALIGHTGREEN,EGALIGHTCYAN,
  419.     EGALIGHTRED,EGALIGHTMAGENTA,EGAYELLOW,EGAWHITE  ));
  420.  
  421.    procedure Abort (Msg:String);
  422.    begin
  423.      RestoreCRTMode;
  424.      CloseGraph;
  425.      Writeln(Msg);
  426.      Writeln (' press enter to leave ...');
  427.      Readln;
  428.      Halt(1);
  429.    end;
  430.  
  431. begin
  432.   InitGraph(driver,mode,Path);
  433.   ErrorCode := GraphResult;               { error? }
  434.   if ErrorCode <> grOk then
  435.      Abort('Graphics error: '+ GraphErrorMsg(ErrorCode));
  436.   G_MaxColor := GetMaxColor;  { Get the maximum allowable drawing color }
  437.   EgaPalette.Size:=G_MaxColor;{ adjust length of standard  palette      }
  438.   setallpalette(EGApalette);  { inform BGI                              }
  439.   InitTurtle;                 { Set up the Turtle                       }
  440. end;
  441.  
  442. Procedure InitTurtle;
  443. begin
  444.   G_MaxColor := GetMaxColor;  { Get the maximum allowable drawing color }
  445.   G_MaxX := GetMaxX;          { Get screen resolution values }
  446.   G_MaxY := GetMaxY;
  447.   TurtleWindow(G_MaxX div 2,G_MaxY div 2,G_MaxX,G_MaxY);
  448.   ResetTurtle;
  449. end;
  450.  
  451.  
  452. procedure ClearScreen;
  453. begin
  454.   _HideTurtle;
  455.   Graph.ClearViewport;
  456.   _ShowTurtle;
  457.   Home
  458. end;
  459.  
  460. procedure FillScreen (Color:Byte);
  461. begin
  462.   _HideTurtle;
  463.   SetFillstyle(Solidfill,Color);
  464.   Graph.Bar3d(0,0,2*T_WinHiX,2*T_WinHiY,0,false);
  465.   _ShowTurtle;
  466.   Home
  467. end;
  468.  
  469. procedure Back(Dist: Integer);
  470. begin
  471.   Forwd(-Dist)
  472. end;
  473.  
  474. procedure Forwd(Dist: Integer);
  475. var NewX,NewY,NewXs,NewYs:Integer;
  476.  
  477.     procedure DoWrap(var X,Y:Integer);
  478.     var Xs,Ys,Xn,Yn:Integer;
  479.     begin
  480.       Xs:=X;Ys:=Y;
  481.       Xn:=T_PosX;Yn:=T_PosY;
  482.       While X <T_WinLoX do begin Inc(X,-T_WinLoX+T_WinHiX); Xn:=T_WinHiX end;
  483.       While X >T_WinHiX do begin Dec(X,-T_WinLoX+T_WinHiX); Xn:=T_WinLoX end;
  484.       While Y <T_WinLoY do begin Inc(Y,-T_WinLoY+T_WinHiY); Yn:=T_WinHiY end;
  485.       While Y >T_WinHiY do begin Dec(Y,-T_WinLoY+T_WinHiY); Yn:=T_WinLoY end;
  486.       If (Xs <>X) Or (Ys <>Y) then
  487.         begin
  488.           Xn:=ToScreenX(Xn);Yn:=ToScreenY(Yn);
  489.           Graph.MoveTo(Xn,Yn);
  490.         end;
  491.     end;
  492.  
  493. begin
  494.   _HideTurtle;
  495.   NewX:= T_PosX+ (LongInt(Dist)*FastCos(90-T_Heading)) div 10000;
  496.   NewY:= T_PosY+ (LongInt(Dist)*FastSin(90-T_Heading)) div 10000;
  497.   If T_Wrap then DoWrap (NewX,NewY);
  498.   NewXs:=ToScreenX(NewX);NewYs:=ToScreenY(NewY);
  499.   If T_PenDown then
  500.      Graph.LineTo(ToScreenX(NewX),ToScreenY(NewY))
  501.   else
  502.      Graph.MoveTo(ToScreenX(NewX),ToScreenY(NewY));
  503.   T_PosX:=NewX;
  504.   T_PosY:=NewY;
  505.   _ShowTurtleDelay
  506. end;
  507.  
  508. function  Heading: Integer;
  509. begin
  510.   Heading:=T_Heading
  511. end;
  512.  
  513. procedure HideTurtle;
  514. begin
  515.  If T_Visible then
  516.    begin
  517.      _HideTurtle;
  518.      T_Visible:=False
  519.    end
  520. end;
  521.  
  522. procedure Home;
  523. begin
  524.   _HideTurtle;
  525.   T_PosX:=0;
  526.   T_PosY:=0;
  527.   Graph.MoveTo(ToScreenX(0),ToScreenY(0));
  528.   T_Heading:=0;
  529.   _ShowTurtle;
  530. end;
  531.  
  532. procedure NoWrap;
  533. begin
  534.   T_Wrap:=False
  535. end;
  536.  
  537. procedure PenDown;
  538. begin
  539.   T_PenDown:=True
  540. end;
  541.  
  542. procedure PenUp;
  543. begin
  544.   T_PenDown:=false
  545. end;
  546.  
  547. procedure SetHeading(Angle: Integer);
  548. begin
  549.   _HideTurtle;
  550.   T_Heading:=Angle mod 360;  { avoid runtime errors in fastSin calls}
  551.   _ShowTurtleDelay
  552. end;
  553.  
  554. procedure SetPenColor(Color: Integer);
  555. begin
  556.   _HideTurtle;
  557.   T_PenColor:=Color and G_MaxColor;
  558.   SetColor(T_PenColor);
  559.   _ShowTurtle
  560. end;
  561.  
  562. procedure SetPosition(X,Y: Integer);
  563. begin
  564.  _HideTurtle;
  565.   T_PosX:=X;
  566.   T_PosY:=Y;
  567.   Graph.MoveTo(ToScreenX(X),ToScreenY(Y));
  568.   _ShowTurtleDelay
  569. end;
  570.  
  571. procedure ShowTurtle;
  572. begin
  573.   If Not T_Visible then
  574.     begin
  575.        T_Visible :=True;
  576.        _ShowTurtleDelay
  577.     end
  578. end;
  579.  
  580. procedure TurnLeft(Angle: Integer);
  581. begin
  582.   SetHeading(T_Heading - Angle);
  583. end;
  584.  
  585. procedure TurnRight(Angle: Integer);
  586. begin
  587.   TurnLeft(-Angle)
  588. end;
  589.  
  590. procedure TurtleDelay(Delay: integer);
  591. begin
  592.   T_Delay:=Delay
  593. end;
  594.  
  595. procedure TurtleWindow(X,Y,W,H: Integer);
  596. begin
  597.   T_WinOrgX:=X;
  598.   T_WinOrgY:=Y;
  599.   T_WinLoX:= - W div 2;
  600.   T_WinLoY:= - H div 2;
  601.   T_WinHiX:= + W div 2;
  602.   T_WinHiY:= + H div 2;
  603. end;
  604.  
  605. function  TurtleThere: Boolean;
  606. begin
  607.   TurtleThere:=T_Visible and PtInRect(T_PosX,T_PosY,T_WinLoX,T_WinLoY,T_WinHiX,T_WinHiY)
  608. end;
  609.  
  610. procedure Wrap;
  611. begin
  612.  T_Wrap:=True
  613. end;
  614.  
  615. function  Xcor: Integer;
  616. begin
  617.  XCor:=T_PosX
  618. end;
  619.  
  620. function  Ycor: Integer;
  621. begin
  622.  YCor:=T_PosY
  623. end;
  624.  
  625. procedure TurtleBox (aColor:Byte);
  626. var Save:Integer;
  627. begin
  628.   Save:=GetColor;
  629.   SetColor(aColor);
  630.   Rectangle(ToScreenX(T_WinLoX),
  631.             ToScreenY(T_WinHiY),
  632.             ToScreenX(T_WinHiX),
  633.             ToScreenY(T_WinLoY));
  634.   SetColor(Save)
  635. end;
  636.  
  637. { HIDE THE TURTLE DURING STANDARD BGI CALLS }
  638.  
  639. procedure ClearDevice;
  640. begin  _HideTurtle;Graph.ClearDevice ;_ShowTurtle end;
  641. procedure ClearViewPort;
  642. begin  _HideTurtle;Graph.ClearViewPort ;_ShowTurtle end;
  643. { *** point-oriented routines *** }
  644. procedure PutPixel(X, Y : integer; Pixel : word);
  645. begin  _HideTurtle;Graph.PutPixel(X,Y,Pixel) ;_ShowTurtle end;
  646. function  GetPixel(X, Y : integer) : word;
  647. begin  _HideTurtle;GetPixel:=Graph.GetPixel(X,Y) ;_ShowTurtle end;
  648.  
  649. procedure LineTo(X, Y : integer);
  650. begin  _HideTurtle;Graph.LineTo(X,Y) ;_ShowTurtle end;
  651. procedure LineRel(Dx, Dy : integer);
  652. begin  _HideTurtle;Graph.LineRel(Dx,Dy) ;_ShowTurtle end;
  653. procedure MoveTo(X, Y : integer);
  654. begin  _HideTurtle;Graph.MoveTo(X,Y) ;_ShowTurtle end;
  655. procedure MoveRel(Dx, Dy : integer);
  656. begin  _HideTurtle;Graph.MoveRel(Dx,Dy) ;_ShowTurtle end;
  657. procedure Line(x1, y1, x2, y2 : integer);
  658. begin  _HideTurtle;Graph.Line(x1,y1,x2,y2) ;_ShowTurtle end;
  659.  
  660. procedure Rectangle(x1, y1, x2, y2 : integer);
  661. begin  _HideTurtle;Graph.Rectangle(x1,y1,x2,y2) ;_ShowTurtle end;
  662. procedure Bar(x1, y1, x2, y2 : integer);
  663. begin  _HideTurtle;Graph.Bar(x1,y1,x2,y2) ;_ShowTurtle end;
  664. procedure Bar3D(x1, y1, x2, y2 : integer; Depth : word; Top : boolean);
  665. begin  _HideTurtle;Graph.Bar3D(x1,y1,x2,y2,Depth,Top) ;_ShowTurtle end;
  666. procedure DrawPoly(NumPoints : word; var PolyPoints);
  667. begin  _HideTurtle;Graph.DrawPoly(NumPoints,PolyPoints) ;_ShowTurtle end;
  668. procedure FillPoly(NumPoints : word; var PolyPoints);
  669. begin  _HideTurtle;Graph.FillPoly(NumPoints,PolyPoints) ;_ShowTurtle end;
  670. procedure FloodFill(X, Y : integer; Border : word);
  671. begin  _HideTurtle;Graph.FloodFill(X,Y,Border) ;_ShowTurtle end;
  672.  
  673. procedure Arc(X, Y : integer; StAngle, EndAngle, Radius : word);
  674. begin  _HideTurtle;Graph.Arc(X,Y,StAngle,EndAngle,Radius) ;_ShowTurtle end;
  675. procedure Circle(X, Y : integer; Radius : word);
  676. begin  _HideTurtle;Graph.Circle(X,Y,Radius) ;_ShowTurtle end;
  677. procedure Ellipse(X, Y : integer; StAngle, EndAngle : word; XRadius, YRadius  : word);
  678. begin  _HideTurtle;Graph.Ellipse(X,Y,StAngle,EndAngle,XRadius,YRadius) ;_ShowTurtle end;
  679. procedure FillEllipse(X, Y : integer;  XRadius, YRadius  : word);
  680. begin  _HideTurtle;Graph.FillEllipse(X,Y,XRadius,YRadius) ;_ShowTurtle end;
  681. procedure PieSlice(X, Y : integer; StAngle, EndAngle, Radius : word);
  682. begin  _HideTurtle;Graph.PieSlice(X,Y,StAngle,EndAngle,Radius) ;_ShowTurtle end;
  683. procedure Sector(X, Y : Integer; StAngle, EndAngle, XRadius, YRadius : word);
  684. begin  _HideTurtle;Graph.Sector(X,Y,StAngle,EndAngle,XRadius,YRadius) ;_ShowTurtle end;
  685.  
  686. procedure GetImage(x1, y1, x2, y2 : integer; var BitMap);
  687. begin  _HideTurtle;Graph.GetImage(X1,Y1,X2,Y2,BitMap); _ShowTurtle end;
  688. procedure PutImage(X, Y : integer; var BitMap; BitBlt : word);
  689. begin  _HideTurtle;Graph.PutImage(X,Y,BitMap,BitBlt); _ShowTurtle end;
  690.  
  691. procedure OutText(TextString : string);
  692. begin  _HideTurtle;Graph.OutText(TextString); _ShowTurtle end;
  693. procedure OutTextXY(X, Y : integer; TextString : string);
  694. begin  _HideTurtle;Graph.OutTextXY(X,Y,TextString); _ShowTurtle end;
  695.  
  696.  
  697. end.
  698.  
  699.