Advertisement
Mysoft

Untitled

May 31st, 2016
596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define fbc -s gui
  2.  
  3. #include "fbgfx.bi"
  4.  
  5. #define ToNum(_N) ((_N) shr 8)
  6. #define ToFix(_N) (cint((_N)*256))
  7. #define iRnd(_N) cint(int(rnd*(_N)))
  8.  
  9. type DotStruct
  10.   iX as integer
  11.   iY as integer
  12.   iSX as integer
  13.   iSY as integer
  14.   iColor as integer
  15.   iNext as integer
  16. end type
  17.  
  18. '=== Configuration ===
  19. 'iKeepScreen = -1 > Start Full Black
  20. 'iKeepScreen =  0 > Gradually Clears
  21. 'iKeepScreen =  1 > Keep Background
  22. dim shared as integer iDots=4,iLines=7,iKeepScreen=1
  23. dim shared as integer iColorStart=12,iColorAdvance=3
  24. '=====================
  25.  
  26. dim shared as integer iScrWid=640,iScrHei=480,iFixWid,iFixHei,iSpeed
  27. redim shared as DotStruct tDots(iLines-1,iDots-1)
  28.  
  29. sub Advance( byref tDot as DotStruct , iAmountFix as integer )  
  30.  
  31.   tDot.iX += ToNum(tDot.iSX * iAmountFix)
  32.   tDot.iY += ToNum(tDot.iSY * iAmountFix)
  33.   if tDot.iX < 0 then tDot.iX = -tDot.iX: tDot.iSX = -tDot.iSX
  34.   if tDot.iX >= iFixWid then tDot.iX = ((iFixWid*2)-2)-tDot.iX: tDot.iSX = -tDot.iSX
  35.   if tDot.iY < 0 then tDot.iY = -tDot.iY: tDot.iSY = -tDot.iSY
  36.   if tDot.iY >= iFixHei then tDot.iY = ((iFixHei*2)-2)-tDot.iY: tDot.iSY = -tDot.iSY
  37.  
  38. end sub
  39.  
  40. sub AdvanceAllDots( fAdvance as single )
  41.   for iD as integer = 0 to iDots-1
  42.     for iL as integer = 0 to iLines-1
  43.      
  44.       Advance( tDots(iL,iD) , fAdvance*iSpeed )
  45.      
  46.       tDots(iL,iD).iNext += ToFix(fAdvance)
  47.       while tDots(iL,iD).iNext >= ToFix(16)
  48.         tDots(iL,iD).iColor += iColorAdvance
  49.         if tDots(iL,iD).iColor > 15 then tDots(iL,iD).iColor -= 7
  50.         tDots(iL,iD).iNext -= ToFix(16)
  51.       wend        
  52.        
  53.        
  54.     next iL
  55.   next iD  
  56. end sub
  57.  
  58. sub InitializeAllDots()
  59.  
  60.   var iAdvance = (ToFix(16)*256)\iSpeed
  61.  
  62.   for iD as integer = 0 to iDots-1    
  63.    
  64.     #define iDirection (((-1+iRnd(2)) or 1)*iSpeed)
  65.     tDots(0,iD) = type( iRnd(iFixWid) , iRnd(iFixHei) ,  iDirection , iDirection , iColorStart )  
  66.    
  67.     for iL as integer = 1 to iLines-1
  68.       tDots(iL,iD) = tDots(iL-1,iD)
  69.       tDots(iL,iD).iColor += iColorAdvance
  70.       if tDots(iL,iD).iColor > 15 then tDots(iL,iD).iColor -= 7
  71.       Advance( tDots(iL,iD) , iAdvance )      
  72.     next iL  
  73.    
  74.   next iD
  75.  
  76. end sub
  77.  
  78. sub DrawAllLines( iJustClear as integer = 0)
  79.  
  80.   var iSkip = iif(iJustClear,1,2)
  81.  
  82.   for iY as integer = -1 to 1 step iSkip
  83.     for iX as integer = -1 to 1 step 1'iSkip
  84.      
  85.       for iL as integer = 0 to iLines-1    
  86.         var iD = 0, iC = iif(iJustClear,(iJustClear=1) and 17,tDots(iL,0).iColor and 7)
  87.         for iD = 0 to iDots-2
  88.           line ( ToNum(tDots(iL,iD).iX)+iX , ToNum(tDots(iL,iD).iY)+iY )- _
  89.           ( ToNum(tDots(iL,iD+1).iX)+iX , ToNum(tDots(iL,iD+1).iY)+iY ), iC
  90.         next iD
  91.         line ( ToNum(tDots(iL,iD).iX)+iX , ToNum(tDots(iL,iD).iY)+iY )- _
  92.         ( ToNum(tDots(iL,0).iX)+iX , ToNum(tDots(iL,0).iY)+iY ), iC
  93.       next iL
  94.      
  95.     next iX
  96.   next iY
  97.  
  98.   if iJustClear then exit sub
  99.    
  100.   for iL as integer = 0 to iLines-1    
  101.     var iC = tDots(iL,0).iColor, iD = 0
  102.     for iD = 0 to iDots-2
  103.       line ( ToNum(tDots(iL,iD).iX) , ToNum(tDots(iL,iD).iY) )- _
  104.       ( ToNum(tDots(iL,iD+1).iX) , ToNum(tDots(iL,iD+1).iY) ), iC
  105.     next iD
  106.     line ( ToNum(tDots(iL,iD).iX) , ToNum(tDots(iL,iD).iY) )- _
  107.     ( ToNum(tDots(iL,0).iX) , ToNum(tDots(iL,0).iY) ), iC
  108.   next iL
  109.  
  110. end sub
  111.  
  112. screeninfo iScrWid,iScrHei
  113. screencontrol(fb.SET_DRIVER_NAME,"GDI")
  114. screenres iScrWid,iScrHei,8,,fb.GFX_HIGH_PRIORITY or iif(iKeepScreen>=0,fb.GFX_SHAPED_WINDOW,fb.GFX_NO_FRAME)
  115. screencontrol(fb.SET_WINDOW_POS,0,0)
  116.  
  117. for iN as integer = 1 to 6
  118.   dim as integer R,G,B
  119.   palette get (iN or 8),R,G,B
  120.   palette iN,R\3,G\3,B\3
  121. next iN
  122.  
  123. iFixWid=ToFix(iScrWid)
  124. iFixHei=ToFix(iScrHei)
  125. iSpeed = ( ToFix(iScrWid+iScrHei) \ iScrWid )
  126.  
  127. InitializeAllDots()
  128.  
  129. dim as double TMR
  130. do
  131.  
  132.   if abs(timer-TMR) > 1/2 then TMR = timer
  133.   var fNewTMR = timer
  134.  
  135.   screenlock
  136.    
  137.   DrawAllLines(1+(iKeepScreen and 1))
  138.    
  139.   #if 1 'TimeBased Movement
  140.     AdvanceAllDots( (fNewTMR-TMR)/(1/60) )
  141.     TMR = fNewTMR
  142.   #else 'FrameBased Movement (compensated)
  143.     while (timer-TMR) > 1/60
  144.       AdvanceAllDots( 1 )
  145.       TMR += 1/60
  146.     wend
  147.   #endif  
  148.  
  149.   DrawAllLines()
  150.  
  151.   screenunlock
  152.  
  153.   'screensync  
  154.   sleep (900\iSpeed)+1,1
  155.  
  156. loop until len(inkey$)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement