Dark Bit Factory & Gravity

PROGRAMMING => Other languages => Yabasic => Topic started by: rain_storm on February 09, 2007

Title: Shockwaves FB Fire Effect in Yabasic
Post by: rain_storm on February 09, 2007
Shockwave wrote this in Freebasic I attempted to translate it into Yabasic. I did this for three reasons

1) To learn how to make a really cool fire effect
2) To learn how to make a really cool fire effect
3) To learn how to make a really cool fire effect

also to cut my teeth with Freebasic by comparing the same code in both Freebasic and Yabasic
man it runs at full speed in the FB but cripples yab even with the resolutions set really low

anyway I thought I would post it all credit goes to Shocky for this one

Code: [Select]

resx = 320
resy = 240
sz = 640/resx
open window 640, 512

dim buffer(resx*resy)
dim flame_buffer(resx*resy)
dim rd(resx), gr(resx), bl(resx)
dim cool_map(resx*resy)
cool_scroll = 0
generate_colours()
make_cool_map()

ticks = 0
oldtime = timer
repeat
   gadd = gadd + 3
   V = 50 + 39*cos(gadd/143)
   scroll_aa()

   m = 120
   rem THIS BIT DRAWS THE FIRE ON THE SCREEN
   for loopy = 0 to resx
      flame_buffer(loopy + (resy/2*resx) ) = resx
   next

   a = 0
   for y = 1 to resy
      for x = 1 to resx a = a + 1
         f = flame_buffer(a)
         setrgb 1, rd(f), gr(f), bl(f)
         fill box x*sz,y*sz to x*sz+sz,y*sz+sz
      next
   next

   ticks = ticks + 1
   ? ticks,"   ", time$
   setdispbuf draw
   draw = 1 - draw
   setdrawbuf draw
   clear window
until (inkey$(0) <> "")
exit

sub scroll_aa()
   d = resx*(resy-4) : rem SCREEN BOUNDS
   rem MOVE OFFSET!
   cool_scroll = cool_scroll + 3
   rem RESET OFFSET IF OFF SCREEN
   if (cool_scroll>resy) cool_scroll = cool_scroll - resy
   rem CONVERT OFFSET INTO VALUE COMPATIBLE WITH OUR 1 DIMENSIONAL ARRAYS.
   c = cool_scroll*resx
   for a = resx to (resx*(resy-2))
      c = c + 1 : rem MOVE ONE LINE DOWN.
      rem IF C OFF SCREEN THEN PUT C BACK AT END OF IST SCAN LINE.
      if (c>d) c = resx
      rem 1280 IS XRES * 2 SO WE SCROLL THE FLAME BUFFER UP 2 LINES AND DARKEN AT SAME TIME TO SAVE SPEED.     
      flame_buffer(a) = flame_buffer(a+resx*2) - cool_map(c+resx*2)
      rem STOP ILLEGAL COLOUR PALETTE REFERENCES.
      if (flame_buffer(a)<0) flame_buffer(a) = 0
   next
   for a = resx to (resx*(resy-2))
      rem CHEAP ANTI ALIAS OF FLAME BUFFER
      b = (flame_buffer(a-resx) + flame_buffer(a+resx) + flame_buffer(a-1) + flame_buffer(a+1))
      b = b/2
      b = b/2
      rem NB, THIS LOOP COULD PROBABLY BE COMBINED WITH ABOVE LOOP TO INCREASE SPEED MORE.
      flame_buffer(a) = b
   next
end sub

sub make_cool_map()
   rem WE'LL PLOT 4000 POINTS IN THE MAP.
   for a = 1 to 4000
      rem RANDOM POINT IN COOL MAP = RANDOM VALUE UP TO resx
      cool_map(ran((resx-1) * (resy-3))+resx) = ran(resx)
   next
   for c = 1 TO 10
      rem THE NUMBER OF AA PASSES, MORE PASSES = BRIGHTER FLAMES.
      for a = resx TO resx*(resy-2)
         rem ACTUALLY DARKENS THE CENTRAL PIXEL SLIGHTLY, IS DESIRABLE..
         b = (cool_map(a-resx)+cool_map(a+resx)+cool_map(a-1)+cool_map(a+1)+cool_map(a))*.2
         if (b<000) b = 0
         if (b>500) b = 500
         cool_map(a) = int(b)
      next
   next
end sub

sub generate_colours()
   rd = 0
   gr = 0
   bl = 0
   for c = 1 to resx
      if (rd<254) rd = rd + sz
      if (c>resx/4) and (gr<255) gr = gr + sz
      if (c>resx/2) and (bl<255) bl = bl + sz
      rd(c) = rd
      gr(c) = gr
      bl(c) = bl
   next
end sub


Title: Re: Shockwaves FB Fire Effect in Yabasic
Post by: Jim on February 09, 2007
I had to turn off 'Force Flush Rate' in the Options to get it to run fast.  But then it looks really cool!  Good effort!

Jim
Title: Re: Shockwaves FB Fire Effect in Yabasic
Post by: Shockwave on February 10, 2007
Once I had turned force flush rate off it ran acceptably fast for me too :)

That's a really nice conversion and I'm very happy that you chose one of my routines to convert!

+++ Karma.
Title: Re: Shockwaves FB Fire Effect in Yabasic
Post by: rain_storm on February 10, 2007
Thankfully all the meaty parts were no problem all the calculations were happy in the move just had to play around with the function headers, type of loops etc. I learnt quite a bit about setting up a proggy in FB in the process.
Title: Re: Shockwaves FB Fire Effect in Yabasic
Post by: Clanky on February 11, 2007
Wow... geez - so many inspiration programs being made in YaBASIC... very nice