home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Amos / amproe2x.dms / in.adf / Compiler_Examples / AMOS_versions / Fractal1.AMOS / Fractal1.amosSourceCode
Encoding:
AMOS Source Code  |  1993-06-16  |  3.7 KB  |  182 lines

  1. ' ---------------------------------  
  2. '
  3. ' AMOSPro Compiler Example 
  4. '
  5. ' Fractal Landscaping 1
  6. '
  7. ' By Jean-Baptiste BOLCATO 
  8. '
  9. ' (c) 1993 Europress Software Ltd. 
  10. '
  11. ' ---------------------------------  
  12. '
  13. '
  14. ' -------------------------------------------------        
  15. ' Remark: Random fractal Landscape Generator     
  16. '         Basic (but fast) outlined version  
  17. '
  18. '         Average Acceleration:  300 % 
  19. '
  20. '         Test configuration: A1200, 6Mb 
  21. '
  22. '         Original AMOS Compiler:  200 % 
  23. ' -------------------------------------------------        
  24.  
  25. ' ---- Variables Init ---- 
  26.  
  27. Set Buffer 50
  28.  
  29. ' Set lens parameters
  30. DIST=500 : ZOM=400
  31.  
  32. ' Time for loops 
  33. TIME=1000
  34.  
  35. ' Coord grid limits  
  36. XF1=-100 : ZF1=-100 : YF1=50
  37. XF2=100 : ZF2=100
  38.  
  39. ' Options screen 
  40. Screen Open 0,320,32,2,Hires
  41. Palette 0,$FFF
  42.  
  43. ' Number of steps  
  44. Input "Grid Subdivision (1 to 32)?:";NS
  45. If NS<1
  46.    NS=1
  47. Else 
  48.    If NS>32
  49.       NS=32
  50.    End If 
  51. End If 
  52.  
  53. Dim X3D(NS,NS),Y3D(NS,NS),Z3D(NS,NS)
  54. Dim XROT(NS,NS),YROT(NS,NS),ZROT(NS,NS)
  55. Dim X2D(NS,NS),Y2D(NS,NS)
  56.  
  57. ' Size of gridding intervals 
  58. ITX=(XF2-XF1)/NS
  59. ITZ=(ZF2-ZF1)/NS
  60.  
  61.  
  62. ' ---- Screen Init ----
  63.  
  64. Screen Open 0,320,256,2,Lowres
  65. Palette 0,$FFF
  66. Screen Display 0,128,45,,
  67. Curs Off : Cls 0 : Hide 
  68. Double Buffer : Autoback 0
  69.  
  70. ' ---- Main Loop ----
  71.  
  72. Degree 
  73. PHI=240
  74. TETA=-60
  75.  
  76. Timer=0
  77.  
  78. ' Init landscape 
  79.  
  80. For J=1 To NS
  81.    For I=1 To NS
  82.       X3D(I,J)=XF1+ITX*I
  83.       Z3D(I,J)=ZF1+ITZ*J
  84.       R=((Abs(I-NS/2)+Abs(J-NS/2))*90)/NS
  85.       Y3D(I,J)=-128*Cos(R)
  86.    Next I
  87. Next J
  88.  
  89. N=0
  90. Repeat 
  91.    
  92.    Cls 0
  93.    
  94.    ' Increment rotation angle   
  95.    Add PHI,2,0 To 359
  96.    
  97.    ' Precalculation of COSs and SINs  
  98.    ' ( *256 to stay in integer mode (faster!))    
  99.    CPHI=Cos(PHI)*256
  100.    SPHI=Sin(PHI)*256
  101.    CTETA=Cos(TETA)*256
  102.    STETA=Sin(TETA)*256
  103.    
  104.    For J=1 To NS
  105.       For I=1 To NS
  106.          
  107.          ' Patch Y - landscape deformation
  108.          Y3D2=Y3D(I,J)*Cos((N-1)*4) : Rem+(SPHI*((I and 2)-1))/4   
  109.          
  110.          ' Calculation of rotated 3D coords of new point
  111.          ' ( /*256 to bring back cos and sin beetween 0->1)     
  112.          ' Rotation (X-Z with PHI)  
  113.          XROT(I,J)=(X3D(I,J)*CPHI+Z3D(I,J)*SPHI)/256
  114.          ZROT(I,J)=(Z3D(I,J)*CPHI-X3D(I,J)*SPHI)/256
  115.          YROT(I,J)=(Y3D2*CTETA+ZROT(I,J)*STETA)/256
  116.          ZROT(I,J)=(ZROT(I,J)*CTETA-Y3D2*STETA)/256
  117.          
  118.          ' Calculation of screen coords 
  119.          X2D(I,J)=160+(XROT(I,J)*ZOM)/(DIST+ZROT(I,J))
  120.          Y2D(I,J)=128+(YROT(I,J)*ZOM)/(DIST+ZROT(I,J))
  121.          
  122.       Next I
  123.    Next J
  124.    
  125.    For J1=2 To NS
  126.       If PHI>=0 and PHI<90
  127.          J=NS-J1+2
  128.       Else 
  129.          If PHI>=90 and PHI<180
  130.             I=J1
  131.          Else 
  132.             If PHI>=180 and PHI<270
  133.                J=J1
  134.             Else 
  135.                I=NS-J1+2
  136.             End If 
  137.          End If 
  138.       End If 
  139.       For I1=2 To NS
  140.          
  141.          If PHI>=0 and PHI<90
  142.             I=I1
  143.          Else 
  144.             If PHI>=90 and PHI<180
  145.                J=I1
  146.             Else 
  147.                If PHI>=180 and PHI<270
  148.                   I=NS-I1+2
  149.                Else 
  150.                   J=NS-I1+2
  151.                End If 
  152.             End If 
  153.          End If 
  154.          
  155.          ' Draw outlined face 
  156.          Ink 15
  157.          Polygon X2D(I,J),Y2D(I,J) To X2D(I-1,J),Y2D(I-1,J) To X2D(I-1,J-1),Y2D(I-1,J-1) To X2D(I,J-1),Y2D(I,J-1)
  158.          Ink 0
  159.          Polyline X2D(I,J),Y2D(I,J) To X2D(I-1,J),Y2D(I-1,J) To X2D(I-1,J-1),Y2D(I-1,J-1) To X2D(I,J-1),Y2D(I,J-1) To X2D(I,J),Y2D(I,J)
  160.          
  161.       Next I1
  162.    Next J1
  163.    
  164.    Screen Swap 
  165.    Wait Vbl 
  166.    
  167.    Inc N
  168.    
  169. Until Timer>=TIME
  170. T#=Timer
  171.  
  172. ' --- Final Report --- 
  173.  
  174. Autoback 1 : Paper 0 : Pen 1
  175. Print "  Needs";T#/50;" seconds for";N;" loops."
  176. Print "          ( =";T#/N;" VBLs )"
  177. Print 
  178. Print "    Press mouse key to end"
  179. Repeat 
  180.    Multi Wait 
  181. Until Mouse Key or(Inkey$<>"")
  182. End