Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' Flame test #2 by Conexion
  2. ' With assistance from ##Freebasic
  3. ' Extra help: Mysoft
  4.  
  5. #Include "fbgfx.bi"
  6. Randomize , 1
  7.  
  8. 'Adjustables
  9. Dim As Single fTrail = 1 / 4.1 'Adjust this to adjust the fire trail
  10. Dim As Integer spnRadius = 80 ' Size of the spinner
  11. Dim As Integer spnDegrees = 5 ' Degrees Clockwise
  12.  
  13. Const fpsLimit = 75
  14. Const pi = 3.14159265 'Shouldn't need any more than that
  15.  
  16. Dim As Integer ScrW = 800, ScrH = 600
  17. Dim As UByte CharH = 8, CharW = 8
  18.  
  19. ScreenRes ScrW, ScrH, 8, , fb.gfx_high_priority
  20.  
  21. 'Set up the pallete
  22. 'xPal is the counter
  23. 'bPal adds extra blue/brightness
  24. Dim As UByte xPal = 255 'Set it so when xPal +=1 happens, you get 0
  25. Dim As UByte bPal = 0
  26.  
  27. Dim As Integer fadewhite = 170
  28. Do
  29.     xPal += 1
  30.     If xPal < 64 Then
  31.         Palette xPal, xPal*4, xPal, 0
  32.     Else
  33.         If xPal > 192 Then
  34.             bPal += 4
  35.         end If
  36.         Palette xPal, 255, xPal, bPal
  37.     end if
  38.    
  39. Loop Until xPal = 255
  40.  
  41. /'Palette test
  42. For iii As Integer = 0 To 255
  43.     Line (iii*2.5+10, 15)-(iii*2.5+30, 40), iii, bf
  44.     Dim As Integer ir, ig, ib
  45.     Palette Get iii, ir, ig, ib
  46. Next
  47. '/
  48.  
  49. 'Set up the Image Buffer
  50. Dim As fb.image Ptr ImgBuff = ImageCreate(ScrW, (ScrH + 4) / 2)
  51.  
  52.  
  53. 'Spinner Variables
  54. Dim As Single spnOldX, spnOldY, spnX, spnY = spnRadius
  55. Dim As Single spnAngle = spnDegrees * -0.017453 'Degrees to Rads
  56. Dim As Integer spnVX = ScrW / 2, spnVY = ScrH / 4 ' Center the Spinner
  57.  
  58. 'Precalculate the distance to each pixel we need to average
  59. Dim As Integer calcDL = ScrW - 1
  60. Dim As Integer calcD = ScrW
  61. Dim As Integer calcDR = ScrW + 1
  62. Dim As Integer calcDD = ScrW Shl 1
  63.  
  64. 'Fire trail variables
  65. Dim As Integer fX, fY, fZ, fColor
  66.  
  67. ' FPS Vars
  68. Dim As Integer fpsX, fpsY, fps, fpsNew, fpsSeconds
  69. fpsX = (ScrW - len(fps)*CharW)
  70. fpsY = (ScrH - CharH) - 32
  71.  
  72. Dim As Double fpsStart
  73. Dim As Integer fpslSleep
  74. Dim As Double fpslStart
  75. Dim As Double fpslV = 1.0 / fpsLimit
  76.  
  77. Do
  78.     ' Start our timer
  79.     fpslStart = Timer
  80.    
  81.     ScreenLock
  82.     ' Lets get the spinner down first!
  83.     spnOldX = spnX
  84.     spnOldY = spnY
  85.    
  86.     ' Calculate the rotation coordinates
  87.     spnX = (spnOldX * Cos(spnAngle)) + (spnOldY * Sin(spnAngle))
  88.     spnY = (spnOldY * Cos(spnAngle)) - (spnOldX * Sin(spnAngle))
  89.    
  90.     ' Draw it, translated "V" distance. Also, half the arc/shape
  91.     ' for when we stretch the image on the Y-axis.
  92.     Circle ImgBuff, (spnX + spnVX, spnY / 2 + spnVY), 8, 255,,,.5
  93.    
  94.     ' The Screen Buffer
  95.     Dim As UByte Ptr ScrBuff = ScreenPtr
  96.     ' The pixel part of ImgBuff
  97.     Dim As UByte Ptr ImgPix = Cast(any Ptr, ImgBuff+1)
  98.    
  99.     ' Random dots on the bottom line
  100.     Dim As UByte Ptr BotLine = ImgPix
  101.     BotLine += ScrW * CInt((ScrH-1)/2)
  102.    
  103.     dim as ubyte ptr SpecksPtr = cast(any ptr,ImgBuff+1)
  104.     For ranLine As Integer = 0 To ScrW
  105.         BotLine[ranLine] = (Rnd * 255)
  106.        
  107.         'Extra specks
  108.         SpecksPtr[rnd*(scrw*(scrh/2-5))] = rnd*32
  109.     Next
  110.    
  111.     ' Circle Flares
  112.     circle ImgBuff,(rnd*scrw,rnd*(scrh*3)),Rnd*20, Rnd*6, , (Rnd*pi)*2 ,Rnd*0.9,f
  113.     circle ImgBuff,(rnd*scrw,rnd*(scrh*2)),Rnd*10, Rnd*10, , ,0.5,f
  114.    
  115.     ' Output FPS with a shadow
  116.     Draw String ImgBuff, (fpsX - 2, (fpsY - 2) / 2), Str(fps), 20
  117.     Draw String ImgBuff, (fpsX - 2, (fpsY + 2) / 2), Str(fps), 20
  118.     Draw String ImgBuff, (fpsX + 2, (fpsY - 2) / 2), Str(fps), 20
  119.     Draw String ImgBuff, (fpsX + 2, (fpsY + 2) / 2), Str(fps), 20
  120.     Draw String ImgBuff, (fpsX, fpsY / 2), Str(fpsNew), 254
  121.  
  122.     ' Filter Time!
  123.     ' Fire is calculated by adding the 3 pixels touching the bottom of any pixel
  124.     ' As well as one pixel two pixels down, then finding the average.
  125.     ' fX, fY, fZ, fColor
  126.     'Dim As Integer calcDL = ScrW - 1
  127.     'Dim As Integer calcD = ScrW
  128.     'Dim As Integer calcDR = ScrW + 1
  129.     'Dim As Integer calcDD = ScrW Shl 2
  130.     Dim As UByte Ptr fT = ImgPix
  131.    
  132.     For fY = 0 To (ScrH/2) - 1
  133.         For fX = 0 To ScrW - 1
  134.             fColor = (fT[calcDL] + fT[calcD] + fT[calcDR] + fT[calcDD]) * fTrail
  135.             *fT = fColor
  136.             fT += 1
  137.         Next
  138.     Next
  139.  
  140.     /' Draw ImgBuff at standard
  141.     for PY as integer = 0 to (Scrh/2)-1
  142.         for PX as integer = 0 to ScrW-1
  143.             *ScrBuff = *ImgPix
  144.             ScrBuff[ScrW] = *ImgPix
  145.             ScrBuff += 1: ImgPix += 1
  146.         Next       
  147.     Next'/
  148.    
  149.     /' Draw ImgBuff at 2*Y
  150.     for PY as integer = 0 to (Scrh/2)-1
  151.         for PX as integer = 0 to ScrW-1
  152.             *ScrBuff = *ImgPix
  153.             ScrBuff[ScrW] = *ImgPix
  154.             ScrBuff += 1: ImgPix += 1
  155.         next
  156.         scrbuff += ScrW    
  157.     Next'/
  158.    
  159.     'ASM option
  160.       asm
  161.     mov edi,[ScrBuff]      'Get Screen Buffer pointer
  162.     mov esi,[ImgPix]       'Get Image Buffer pointer
  163.     mov eax,[ScrW]         'Get screen Width
  164.     mov ebx,[ScrH]         'Get Screen height
  165.     mov edx,eax            'make a copy of width
  166.     shr eax,2              'convert pixels/line to dwords/line
  167.     shr ebx,1              'only half of the screen will be read
  168.     NextLine:               'Starting another line
  169.     mov ecx,eax            'loading pixels per line (in dwords)
  170.     rep movsd              'copying those pixels
  171.     sub esi,edx            'we will repeat it again
  172.     mov ecx,eax            'so pixels per line again
  173.     rep movsd              'and copying those pixels (2:1)
  174.     dec ebx                'one line is done.. there are more?
  175.     jnz NextLine           'yes? than keep duplicating
  176.   end Asm '
  177.  
  178.     ScreenUnLock
  179.        
  180.     ' Adjust for our FPS limit
  181.     fpslSleep = CInt((fpslStart + fpslV - Timer) * 1000.0)
  182.     If fpslSleep > 1 Then
  183.         Sleep fpslSleep, 1
  184.     Else
  185.         'Let's not be a memory hog
  186.         Sleep 1
  187.     end If
  188.    
  189.     ' Calculate actual FPS
  190.     fps += 1
  191.     'fpsStart + 1 = One second going by
  192.     If fpsStart + 1 < Timer Then
  193.         fpsNew = fps
  194.         fps = 0
  195.         fpsSeconds += 1
  196.         fpsStart = Timer
  197.     end If
  198.    
  199. Loop Until InKey <> ""
  200.  
  201. ImageDestroy(ImgBuff)
  202. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement