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

  1. PROGRAM Fractal;
  2. {A fractal drawing demonstration program for THOR's windowlib.
  3.  © 1997 THOR-Software inc.}
  4. {$I "include:utils/windowlib.i"}
  5.     
  6.  
  7. CONST
  8.     maxlevel    =    10;        {maximal level of iterations}
  9.     
  10. TYPE
  11.     AffineMapping    =    RECORD        {a general affine mapping: matrix plus shift}
  12.         LinearMapping    :    ARRAY[1..2,1..2] OF REAL;
  13.         Movement    :    ARRAY[1..2] OF REAL;
  14.     END;
  15.     
  16.     Point        =    RECORD        {a pair of coordinates}
  17.         x        :    REAL;
  18.         y        :    REAL;
  19.     END;
  20.     
  21.     
  22. VAR
  23.     maps            :    ARRAY[1..4] OF AffineMapping;    
  24.             {we need for maps for these}
  25.  
  26.     level            :    INTEGER;
  27.     window            :    WindowPtr;    
  28.             {where to display}
  29.  
  30.     base            :    Point;
  31.     
  32.     
  33.  
  34. {apply the affine mapping to the point}    
  35. PROCEDURE MapPoint(m : AffineMapping;VAR p : Point);
  36. BEGIN
  37.     p.x:=p.x*m.LinearMapping[1][1]+p.y*m.LinearMapping[1][2]+m.Movement[1];
  38.     p.y:=p.x*m.LinearMapping[2][1]+p.y*m.LinearMapping[2][2]+m.Movement[2];
  39. END;
  40.  
  41. {draw a point. Scale it.}
  42. PROCEDURE PlotPoint(w : WindowPtr;p : Point);
  43. BEGIN
  44.     Color(w,1);                {define color}
  45.     Plot(w,p.x*24+320,-p.y*12+180);        {plot pixel}
  46. END;
  47.  
  48. {iterate a point}
  49. PROCEDURE Iterate(p : Point);
  50. VAR
  51.     psave        :    Point;
  52.     
  53. BEGIN
  54.     level:=level+1;
  55.     IF level>=maxlevel THEN
  56.         PlotPoint(window,p)
  57.     ELSE BEGIN
  58.         psave:=p;
  59.         MapPoint(maps[1],psave);
  60.         Iterate(psave);
  61.         
  62.         psave:=p;
  63.         MapPoint(maps[2],psave);
  64.         Iterate(psave);
  65.         
  66.         psave:=p;
  67.         MapPoint(maps[3],psave);
  68.         Iterate(psave);
  69.         
  70.         psave:=p;
  71.         MapPoint(maps[4],psave);
  72.         Iterate(psave);
  73.     END;
  74.     
  75.     level:=level-1;
  76. END;
  77.  
  78.  
  79. {the main program}
  80. BEGIN
  81.     InitGraphics;        {setup gfx system}
  82.     
  83.                 {setup the maps}
  84.     WITH maps[1] DO BEGIN
  85.         LinearMapping[1][1]:=0.0;
  86.         LinearMapping[1][2]:=0.0;
  87.         LinearMapping[2][1]:=0.0;
  88.         LinearMapping[2][2]:=0.17;
  89.         Movement[1]:=0.0;
  90.         Movement[2]:=0.0;
  91.     END;
  92.  
  93.     WITH maps[2] DO BEGIN
  94.         LinearMapping[1][1]:=0.84962;
  95.         LinearMapping[1][2]:=0.0255;
  96.         LinearMapping[2][1]:=-0.0255;
  97.         LinearMapping[2][2]:=0.84962;
  98.         Movement[1]:=0.0;
  99.         Movement[2]:=3.0;
  100.     END;
  101.  
  102.  
  103.     WITH maps[3] DO BEGIN
  104.         LinearMapping[1][1]:=-0.1554;
  105.         LinearMapping[1][2]:=0.234;
  106.         LinearMapping[2][1]:=0.19583;
  107.         LinearMapping[2][2]:=0.18648;
  108.         Movement[1]:=0.0;
  109.         Movement[2]:=1.2;
  110.     END;
  111.  
  112.     
  113.     WITH maps[4] DO BEGIN
  114.         LinearMapping[1][1]:=0.1554;
  115.         LinearMapping[1][2]:=-0.235;
  116.         LinearMapping[2][1]:=0.19583;
  117.         LinearMapping[2][2]:=0.18648;
  118.         Movement[1]:=0.0;
  119.         Movement[2]:=3.0;
  120.     END;
  121.  
  122.     {open a window on the workbench}    
  123.     window:=OpenScreenWindow(NIL,0,0,640,200,2+4+8,"Fractal Generator");
  124.     IF window<>NIL THEN BEGIN
  125.         Color(window,1);    {choose color}
  126.         base.x:=0.0;
  127.         base.y:=0.0;
  128.         level:=0;
  129.         Iterate(base);
  130.         
  131.         WaitForClose(window);    {wait until user closes the window}
  132.         CloseAWindow(window);    {shut down}
  133.     END;
  134.     
  135.     ExitGraphics;            {cleanup gfx system}
  136. END.                
  137.  
  138.