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

  1. ' ---------------------------------  
  2. '
  3. ' AMOSPro Compiler Example 
  4. '
  5. ' Multi-Spline's 'Snaky'     
  6. '
  7. ' By Jean-Baptiste BOLCATO 
  8. '
  9. ' Original by Hedwig JANSSENS  
  10. '
  11. ' (c) 1993 Europress Software Ltd. 
  12. '
  13. ' ---------------------------------  
  14. '
  15. '
  16. ' --------------------------------------------       
  17. ' Remark:  A bouncing-splines-made snake   
  18. '
  19. '          Average Acceleration:  510 %  
  20. '
  21. '          Test configuration: A1200, 6Mb  
  22. '
  23. '          Original AMOS Compiler:  350 %  
  24. ' --------------------------------------------         
  25.  
  26.  
  27. ' ---- Variables Init ---- 
  28.  
  29. Set Buffer 5
  30.  
  31. ' Ntsc test
  32. YMAX=253-56*(Ntsc=True)
  33.  
  34. NMAX=17
  35. Dim XT(7,NMAX),YT(7,NMAX),NT(7)
  36. Dim X(NMAX),Y(NMAX),VX(NMAX),VY(NMAX)
  37. P=1
  38.  
  39. ' Randomize starting positions 
  40.  
  41. For I=1 To NMAX
  42.    X(I)=Rnd(318) : Y(I)=Rnd(YMAX)
  43.    VX(I)=((Rnd(1)*2)-1)*4 : VY(I)=((Rnd(1)*2)-1)*6
  44. Next I
  45. '
  46. N2=0 : N=3
  47.  
  48. ' ---- Screen Init ----
  49.  
  50. Screen Open 0,320,YMAX+3,8,LORES
  51. Flash Off : Curs Off : Hide 
  52. For R=0 To 7 : Colour R,256*R*2+16*R : Next R
  53. Colour 7,$FC0
  54. Cls 0
  55.  
  56. ' ---- Main Loop ----
  57.  
  58. Repeat 
  59.    
  60.    ' After every 25 loops, add a spline segment 
  61.    Inc N2 : If N2=25 : Add N,2 : N2=0 : End If 
  62.    
  63.    ' Check screen borders and bounce back 
  64.    For I=1 To N
  65.       X(I)=X(I)+VX(I) : If X(I)>318 or X(I)<1 Then VX(I)=-VX(I)
  66.       Y(I)=Y(I)+VY(I) : If Y(I)>YMAX or Y(I)<1 Then VY(I)=-VY(I)
  67.    Next I
  68.    Ink 0
  69.    For I=1 To NT(P)-2 Step 2
  70.       _SPLINE[XT(P,I),YT(P,I),XT(P,I+1),YT(P,I+1),XT(P,I+2),YT(P,I+2),8]
  71.    Next I
  72.    Ink P
  73.    For I=1 To N-2 Step 2
  74.       _SPLINE[X(I),Y(I),X(I+1),Y(I+1),X(I+2),Y(I+2),8]
  75.    Next I
  76.    Shift Up 320,1,7,1
  77.    
  78.    ' Put coordinates in stack for making a trail
  79.    NT(P)=N
  80.    For I=1 To NT(P)
  81.       XT(P,I)=X(I) : YT(P,I)=Y(I)
  82.    Next I
  83.    Add P,1,1 To 7
  84.    
  85.    Wait Vbl 
  86.    
  87. Until N=NMAX
  88.  
  89. ' --- Final Report --- 
  90.  
  91. T#=Timer
  92. Shift Off 
  93. Home : Paper 0 : Pen 1 : Colour 1,$FFF
  94. Print "     --- Final status report ---     "
  95. Print 
  96. Print "   < Total time ellapsed:";T#/50;"s >   "
  97. Print 
  98. Print "        Press mouse key to end"
  99. Repeat 
  100.    Multi Wait 
  101. Until Mouse Key or(Inkey$<>"")
  102.  
  103. End 
  104.  
  105. ' ---- Procedure SPLINE! ----
  106.  
  107. Procedure _SPLINE[XB,YB,XC,YC,XE,YE,S]
  108.    '  
  109.    ' Inputs: XB,YB  Begin coordinate spline     
  110.    '         XE,YE  End coordinate spline       
  111.    '         XC,YC  Control coordinate spline   
  112.    '         S      Number of Subdivisions for building curve     
  113.    ' Outputs: Plots to current screen in current color  
  114.    '
  115.    FL=0
  116.    For ST=0 To S
  117.       XS1=XB-((XB-XC)*ST)/S : YS1=YB-((YB-YC)*ST)/S
  118.       XS2=XC-((XC-XE)*ST)/S : YS2=YC-((YC-YE)*ST)/S
  119.       XS=XS1-((XS1-XS2)*ST)/S : YS=YS1-((YS1-YS2)*ST)/S
  120.       If FL=0 Then Plot XS,YS : FL=1 Else Draw To XS,YS
  121.    Next ST
  122. End Proc