home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / TURBLE.ZIP / TURBLE2.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1986-03-31  |  5.8 KB  |  255 lines

  1.     {Draws a tree shape.  Notice that although the parameter is type
  2.      real, this is only for the convenience of the procedure.  You can
  3.      enter integer parameters.}
  4.  
  5. Procedure Tree(Height : Real);
  6.  
  7. Var
  8.   SizeFork : Integer;
  9.  
  10. Procedure Vee;
  11. begin
  12.   Turn(-45);
  13.   Go(SizeFork);
  14.   Go(-SizeFork);
  15.   Turn(90);
  16.   Go(SizeFork);
  17.   Go(-SizeFork);
  18.   Turn(-45);
  19. end;
  20.  
  21. Procedure Branch;
  22. begin
  23.   Go(SizeFork + SizeFork div 2);
  24.   Vee;
  25.   Go(SizeFork + SizeFork div 2);
  26.   Vee;
  27.   Go(SizeFork);
  28.   Go(-4 * SizeFork);
  29. end;
  30.  
  31. Procedure Bush;
  32. Var I : Integer;
  33. begin
  34.   Turn(-60);
  35.   For I := 1 to 4 do
  36.     begin
  37.       Branch;
  38.       Turn(30);
  39.     end;
  40.   Branch;
  41.   Turn(-60);
  42. end;
  43.  
  44. begin
  45.   SizeFork := Round(Height / 9);
  46.   Go(5 * SizeFork);
  47.   Bush;
  48.   Go(-5 * SizeFork);
  49. end;
  50.                                
  51.  
  52.     {Draws a spiral.  Since this is a continuous figure, it needs an
  53.      artificial exit to prevent it from spiraling into infinity.}
  54.  
  55. Procedure Spiral(Side, Angle, Increment : Integer);
  56.  
  57. Label Exit;
  58. Var 
  59.   I : integer;
  60.  
  61. begin
  62.   For I := 1 to 32000 do      {The number 32000 prevents it from going...  }
  63.     begin                     {forever if you forget to stop it.           }
  64.       Go(side);
  65.       Turn(angle);
  66.       Side := Side + Increment;
  67.       If Keypressed then Goto Exit;  {Here's the exit.  It won't work if...}
  68.     end;                             {the U+ directive is on.              }
  69. Exit : end;
  70.  
  71.  
  72.    {Draws spirals that inverts until it turns itself inside out.  Makes 
  73.     interesting patterns.}
  74.  
  75. Procedure InSpiral(Side, Angle, Increment : Integer);
  76.  
  77. Label Exit;
  78.  
  79. begin
  80.   Go(side);
  81.   Turn(angle);
  82.   If Keypressed then Goto Exit;     {Exit won't work with U+ directive on.}
  83.   InSpiral(Side, Angle + Increment, Increment);  {Calls itself.           }
  84. exit : end;
  85.  
  86.  
  87.    {Draws a crude snowflake. }
  88.  
  89. Procedure SnowFlake(Size, Level : Real);
  90.  
  91. Procedure Side(Size, Level : Real);
  92.  
  93. Label Exit;
  94.  
  95. Procedure Call;
  96. begin
  97.   Side(Size / 3, Level - 1);
  98. end;
  99.  
  100. begin
  101.   If Level = 0 then
  102.     begin
  103.       Go(Round(Size));
  104.       Goto Exit;
  105.     end;
  106.   Call;
  107.   Turn(-60);
  108.   Call;
  109.   Turn(120);
  110.   Call;
  111.   Turn(-60);
  112.   Call;
  113. Exit : end;
  114.  
  115. Var
  116.   I : Integer;
  117.  
  118. begin
  119.   Pencolor(None);
  120.   Turn(-45);
  121.   Go(Round(Size) div 2);
  122.   Turn(45);
  123.   Pencolor(On);
  124.   For I := 1 to 3 do
  125.     begin
  126.       Turn(120);
  127.       Side(Size,Level);
  128.     end;
  129. end;
  130.  
  131.  
  132.    {The following procedures draw circles using the turtle graphics
  133.     system.  Circles drawn in this manner are not particularly accurate.
  134.     A more accurate (but often slower) routine is provided later. First
  135.     a left circle and a right circle.}
  136.  
  137. Procedure LCircle(Radius : Integer);
  138. Var
  139.   I : Integer;
  140.  
  141. Procedure LBitArc(Radius : Integer);      {Draw a ten-degree left arc.    }
  142. begin
  143.   Turn(-5);
  144.   Go(Round(Radius * Pi / 18));
  145.   Turn(-5);
  146. end;
  147.  
  148. begin
  149.   For I := 1 to 36 do LBitArc(Radius);    {Draw 36 ten-degree arcs.       }
  150. end;
  151.  
  152.  
  153. Procedure RCircle(Radius : Integer);
  154.  
  155. Var
  156.   I : Integer;
  157.  
  158. Procedure RBitArc(Radius : Integer);      {Draw a ten-degree right arc.   }
  159. begin
  160.   Turn(5);
  161.   Go(Round(Radius * Pi / 18));
  162.   Turn(5);
  163. end;
  164.  
  165. begin
  166.   For I := 1 to 36 do RBitArc(Radius);    {Draw 36 ten-degree arcs.       }
  167. end;
  168.  
  169.    {And here is a routine that draws a circle using the starting point
  170.     as the center of the circle.  The previous circle routines start
  171.     at a point on the edge of the circle.}
  172.  
  173. Procedure CCircle(Radius : Integer);
  174.  
  175. Var
  176.   I, Buffer : Integer;
  177.  
  178. begin
  179.   Buffer := ColorOfPen;
  180.   Pencolor(None);
  181.   Go(-Radius);
  182.   Turn(90);
  183.   Pencolor(Buffer);
  184.   LCircle(Radius);
  185.   Pencolor(None);
  186.   Turn(-90);
  187.   Go(Radius);
  188.   PenColor(Buffer);
  189. end;
  190.  
  191.  
  192.    {This is a real circle routine.  It does not use turtle graphics concepts.
  193.     While the previous circle procedures draw polygons with very short sides,
  194.     this procedure actually plots each point on the circle.  It does eight
  195.     quadrants simultaneously to cut down on real number calculations.  You
  196.     can change the Raggedness constant to speed up drawing, but your circle
  197.     will be looser (fewer dots).}
  198.  
  199. Procedure Circle(Radius : Integer);
  200. Var
  201.   X, Y, dX, dY : Integer;
  202.   dA, Rad45, Angle  : Real;
  203.  
  204. Const
  205.   Raggedness = 1;         {Increase to make circle faster and more ragged.}
  206.  
  207. Procedure QuadDot;              {Draw eight points in different quadrants.}
  208. begin
  209.   dot(X + dX,Y + dY);
  210.   dot(X - dX,Y + dY);
  211.   dot(X + dX,Y - dY);
  212.   dot(X - dX,Y - dY);
  213.   dot(X + dY,Y + dX);
  214.   dot(X - dY,Y + dX);
  215.   dot(X + dY,Y - dX);
  216.   dot(X - dY,Y - dX);
  217. end;
  218.  
  219. begin
  220.   X := StartX; Y := StartY;                      
  221.   Dot(X + Radius,Y); Dot(X - Radius,Y);           {Draw first four points.}
  222.   Dot(X,Y + Radius); Dot(X,Y - Radius);
  223.   dA := Raggedness / Radius;                      {Calculate the angle.   }
  224.   Rad45 := 45 * pi / 180;
  225.   Angle := dA;
  226.   While Angle <= Rad45 do
  227.     begin
  228.       dX := round(Radius * cos(Angle));           {Calculate a dot.       }
  229.       dY := round(Radius * sin(Angle));
  230.       QuadDot;                                    {Draw the quadrants.    }
  231.       Angle := Angle + dA;                        {Increment.             }
  232.     end;
  233. end;
  234.  
  235.  
  236.    {Here's a procedure that uses circles.}
  237.  
  238. Procedure Slinky(Size, Bend : Integer);
  239.  
  240. Label Exit;
  241. Var 
  242.   Buffer : Integer;
  243.  
  244. begin
  245.   If KeyPressed then Goto Exit;        {Won't exit if U+ directive is on.}
  246.   RCircle(Size);
  247.   Buffer := ColorOfPen;                {Save color so you can move...    }
  248.   Pencolor(None);                      {...without drawing.              }
  249.   Turn(90);
  250.   Go(10);
  251.   Turn(-90 + Bend);
  252.   Pencolor(Buffer);
  253.   Slinky(Size, Bend);                  {Slinky calls itself.             }
  254. Exit : end;
  255.