home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / Gfx4PCQ.lha / WindowLib / Examples / CircleMaze / CircleMaze.p < prev    next >
Encoding:
Text File  |  1997-02-09  |  1.8 KB  |  86 lines

  1. PROGRAM CircleMaze;
  2. {This program generates a maze consisting of cirular arcs, or a nice pattern
  3.  if you wish. Another example what's possible with the windowlib.
  4.  They are again based on a so called Truchet-Tiling.
  5.  © 1997 THOR-Software}
  6.  
  7. {Include the windowlib and the random generator}
  8.  
  9. {$I "Include:utils/windowlib.i"}
  10. {$I "Include:utils/random.i"}
  11.     
  12.     
  13. CONST
  14.     pi        =    3.14159326;
  15.     radius        =    4;
  16.     size        =    8;
  17.     
  18.     
  19. VAR
  20.     window        :    WindowPtr;
  21.     x,y        :    INTEGER;
  22.     
  23.     
  24. {draw a circulcar arc, giving center position and starting/ending angle}
  25. PROCEDURE DrawArc(mx,my : INTEGER; from,last : INTEGER);
  26. VAR
  27.     i    :    INTEGER;
  28.     arc    :    REAL;
  29.     connect    :    BOOLEAN;
  30.     x,y    :    INTEGER;
  31.     
  32. BEGIN
  33.  
  34.     connect:=FALSE;
  35.     
  36.     FOR i:=from*12 TO last*12 DO BEGIN
  37.         arc:=i*pi/24;
  38.         x:=2*radius*cos(arc)+mx+0.5;
  39.         y:=-radius*sin(arc)+my+0.5;
  40.         IF connect THEN
  41.             DrawTo(window,x,y)    {draw line to last point}
  42.         ELSE    Plot(window,x,y);    {or plot point at the beginning}
  43.         connect:=TRUE;
  44.     END;
  45.     
  46. END;
  47.  
  48. {draw one of two possible tiles consisting of arcs}
  49. PROCEDURE DrawTruchet(x,y : INTEGER;which : BOOLEAN);
  50. BEGIN
  51.     IF which THEN BEGIN
  52.         DrawArc(x,y-size,3,4);
  53.         DrawArc(x+2*size,y,1,2);
  54.     END ELSE BEGIN
  55.         DrawArc(x,y,0,1);
  56.         DrawArc(x+2*size,y-size,2,3);
  57.     END;
  58. END;
  59.  
  60. BEGIN
  61.  
  62.     InitGraphics;    {setup gfx system}
  63.     SelfSeed;    {setup random generator}
  64.  
  65.     {open a window}    
  66.     window:=OpenScreenWindow(NIL,0,0,640,200,2+4+8,"CircleMaze");
  67.     
  68.     IF window<>NIL THEN BEGIN
  69.         Color(window,1);    {choose color}
  70.  
  71.         FOR y:=0 TO (200 DIV size) DO BEGIN
  72.             FOR x:=0 TO (640 DIV (size*2)) DO BEGIN
  73.  
  74.                 IF RangeRandom(1)=0 THEN
  75.                     DrawTruchet(x*size*2,y*size,FALSE)
  76.                 ELSE    DrawTruchet(x*size*2,y*size,TRUE);                                
  77.             END;
  78.         END;
  79.         
  80.         WaitForClose(window);    {wait until user closes the window}
  81.         CloseAWindow(window);    {close it}
  82.     END;
  83.     
  84.     ExitGraphics;            {cleanup gfx system}
  85. END.
  86.