Advertisement
Guest User

Untitled

a guest
Jul 8th, 2017
64
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. Const fpsLimit = 60
  9. Const pi = 3.14159265 'Shouldn't need any more than that
  10.  
  11. Dim As Integer ScrW = 800, ScrH = 600
  12. Dim As UByte CharH = 8, CharW = 8
  13.  
  14. ScreenRes ScrW, ScrH, 8, , fb.gfx_high_priority
  15.  
  16. 'Set up the pallete
  17. 'xPal is the counter
  18. 'bPal adds extra blue/brightness
  19. Dim As UByte xPal = 255 'Set it so when xPal +=1 happens, you get 0
  20. Dim As UByte bPal = 0
  21.  
  22. Dim As Integer fadewhite = 170
  23. Do
  24.     xPal += 1
  25.     If xPal < 64 Then
  26.         Palette xPal, xPal*4, xPal, 0
  27.     Else
  28.         If xPal > 192 Then
  29.             bPal += 4
  30.         end If
  31.         Palette xPal, 255, xPal, bPal
  32.     end if
  33.    
  34. Loop Until xPal = 255
  35.  
  36. /'Palette test
  37. For iii As Integer = 0 To 255
  38.     Line (iii*2.5+10, 15)-(iii*2.5+30, 40), iii, bf
  39.     Dim As Integer ir, ig, ib
  40.     Palette Get iii, ir, ig, ib
  41. Next
  42. '/
  43.  
  44. 'Set up the Image Buffer
  45. Dim As fb.image Ptr ImgBuff = ImageCreate(ScrW, (ScrH + 4) / 2)
  46.  
  47.  
  48. 'Spinner Variables
  49. Dim As Integer spnRadius = 80
  50. Dim As Integer spnDegrees = 11 ' Degrees Clockwise
  51. Dim As Single spnOldX, spnOldY, spnX, spnY = spnRadius
  52. Dim As Single spnAngle = spnDegrees * -0.017453 'Degrees to Rads
  53. Dim As Integer spnVX = ScrW / 2, spnVY = ScrH / 4 ' Center the Spinner
  54.  
  55. 'Precalculate the distance to each pixel we need to average
  56. Dim As Integer calcDL = ScrW - 1
  57. Dim As Integer calcD = ScrW
  58. Dim As Integer calcDR = ScrW + 1
  59. Dim As Integer calcDD = ScrW Shl 2
  60.  
  61. 'Adjust this to adjust the fire trail
  62. Dim As Single fTrail = 1 / 4.2
  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) - 24
  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( UByte Ptr, Cast( UByte Ptr, ImgBuff ) + SizeOf(FB.IMAGE) )
  98.    
  99.     ' Random dots on the bottom line
  100.     Dim As UByte Ptr BotLine = ImgPix
  101.     BotLine += ScrW * CInt((ScrH-2)/2)
  102.     For ranLine As Integer = 0 To ScrW
  103.         BotLine[ranLine] = (Rnd * 255)
  104.     Next
  105.    
  106.     ' Output FPS with a shadow
  107.     Draw String ImgBuff, (fpsX - 1, (fpsY - 1) / 2), Str(fps), 0
  108.     Draw String ImgBuff, (fpsX - 1, (fpsY + 1) / 2), Str(fps), 0
  109.     Draw String ImgBuff, (fpsX + 1, (fpsY - 1) / 2), Str(fps), 0
  110.     Draw String ImgBuff, (fpsX + 1, (fpsY + 1) / 2), Str(fps), 0
  111.     Draw String ImgBuff, (fpsX, fpsY / 2), Str(fpsNew), 254
  112.  
  113.     ' Filter Time!
  114.     ' Fire is calculated by adding the 3 pixels touching the bottom of any pixel
  115.     ' As well as one pixel two pixels down, then finding the average.
  116.     ' fX, fY, fZ, fColor
  117.     'Dim As Integer calcDL = ScrW - 1
  118.     'Dim As Integer calcD = ScrW
  119.     'Dim As Integer calcDR = ScrW + 1
  120.     'Dim As Integer calcDD = ScrW Shl 2
  121.     Dim As UByte Ptr fT = ImgPix
  122.    
  123.     For fY = 0 To (ScrH/2) - 1
  124.         For fX = 0 To ScrW - 1
  125.             fColor = (fT[calcDL] + fT[calcD] + fT[calcDR] + fT[calcDD]) * fTrail
  126.             *fT = fColor
  127.             fT += 1
  128.         Next
  129.     Next
  130.  
  131.     ' Draw ImgBuff at 2*Y
  132.     for PY as integer = 0 to (Scrh/2)-1
  133.         for PX as integer = 0 to ScrW-1
  134.             *ScrBuff = *ImgPix
  135.             ScrBuff[ScrW] = *ImgPix
  136.             ScrBuff += 1: ImgPix += 1
  137.         next
  138.         scrbuff += ScrW    
  139.     Next
  140.  
  141.     ScreenUnLock
  142.        
  143.     ' Adjust for our FPS limit
  144.     fpslSleep = CInt((fpslStart + fpslV - Timer) * 1000.0)
  145.     If fpslSleep > 1 Then
  146.         Sleep fpslSleep, 1
  147.     Else
  148.         'Let's not be a memory hog
  149.         Sleep 1
  150.     end If
  151.    
  152.     ' Calculate actual FPS
  153.     fps += 1
  154.     'fpsStart + 1 = One second going by
  155.     If fpsStart + 1 < Timer Then
  156.         fpsNew = fps
  157.         fps = 0
  158.         fpsSeconds += 1
  159.         fpsStart = Timer
  160.     end If
  161.    
  162. Loop Until InKey <> ""
  163.  
  164. ImageDestroy(ImgBuff)
  165. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement