April 26, 2024, 05:50:33 AM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Fire

Started by GWS, May 02, 2012, 11:41:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

GWS

May 02, 2012, 11:41:29 PM Last Edit: May 05, 2012, 02:50:10 AM by GWS
Hi,

Here's an interesting little program adapted from code by Zappa.

CB is only just fast enough to make it work.  It would probably look better in IWB  :)


' DX Fire - GWS (converted from Zappa code)

def w:window
def style,i,key,Width,Height,run:int
def varW,varH:int
def flame[300,250],x,y,Clr,Random,colors,n:int

declare Rn(low:int,high:int)

autodefine "off"

Width=200
Height=120

style = @NOAUTODRAW

window w,-Width,0,Width,Height,style,0,"Creative Fire",main
setwindowcolor w,rgb(0,0,20)

createscreen(w,Width,Height)

frontpen w,rgb(0,180,255)
setfont w,"Times New Roman",14,700
drawmode w, @TRANSPARENT

centerwindow w

dxfill (w,rgb(0,0,20))
dxflip w

move w,25,30
print w,"Press ESC to Exit"

run = 1

waituntil run = 0
closewindow w
END

main:
select @CLASS
case @idclosewindow
  run = 0
case @idchar
    key = @CODE
if (key = 27) then run = 0
case @iddxupdate
for y = height to 0 step -1
for x = 0 to width step 2
Random = Rn(1,3) :' set random flame color
      Flame[x,y] = Flame[x,y] - Random
      Flame[x,(y - Random)] = Flame[x,y]
      Clr = Flame[x,y] * 5
If Clr < 50 :' make the background black
colors = Rgb(0,0,0)
else
colors = Rgb(255,Clr,0)
endif
pset w,x + random,y,colors :' draw the flames
next x
    next y

    for x = 0 to width
       for y = (height - 10) to height
          Flame[x,y] = 50 :'set color back to yellow
       next y
    next x

dxflip w

endselect
return

sub Rn(low,high)
' generates a random number between Low and High ..
n = int((high - low + 1) * rnd(1.0) + low)
return n



best wishes, :)

Graham

Tomorrow may be too late ..

GWS

Hi,

Zerodog has tried it in IWB ..  :)

http://www.ionicwind.com/forums/index.php?topic=4960.0

It's much faster and the widow size can be increased - but it exposes the limitation of this method.

The 'flames' are not very convincing - the colours not quite right - so I reckon the search for a better method goes on ..

best wishes, :)

Graham
Tomorrow may be too late ..

ZeroDog

Quoteso I reckon the search for a better method goes on ..

Sounds like an idea for a coding challenge called "The Quest for Fire".  Most convincing realtime fire wins the title of "Head Caveman". ;)