Saw this thread:
http://www.ionicwind.com/forums/index.php?topic=4959.msg37803
and thought, I wonder how much faster it can go in IWBasic... Well, it went a bit too fast, so I added a blur effect (from a random snippet I had, sorry cant remember the original author) to slow it down a little.
Here's the result:
' DX Fire - GWS (converted from Zappa code)
' converted to IWBasic + added blur - ZD
def w:window
def style,key,Width,Height,run,count:int
def flame[300,250],x,y,Clr,Random,colors,n:int
int wImage,hImage,oImage
uint p,r,g,b,r2,g2,b2,r3,g3,b3,r4,g4,b4
pointer pImage,pTemp,pUimage,pDimage
declare Rn(low:int,high:int),int
autodefine "off"
Width=200
Height=120
style = @NOAUTODRAW
openwindow w,-Width,0,Width,Height,style,0,"Creative Fire",&main
setwindowcolor w,rgb(0,0,20)
getclientsize w,x,y,width,height
attachscreen(w,Width,Height)
frontpen backbuffer,rgb(0,180,255)
setfont backbuffer,"Times New Roman",14,700
drawmode backbuffer, @TRANSPARENT
centerwindow w
run = 1
do
count++
lockbuffer
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
writepixel x + random,y,colors,BackBuffer :' draw the flames
next x
next y
pImage = getbufferpointer(BackBuffer)
oImage = getbufferpitch(BackBuffer)
wImage = getbufferwidth(BackBuffer)-1
hImage = getbufferheight(BackBuffer)-1
pUimage = pImage
pImage += oImage
pDimage = pImage+oImage
pTemp = pUimage+hImage*oImage
for x = 0 to wImage
#<uint>pUimage[x] = (#<uint>pUImage[x]>>1)&0x7f7f7f
#<uint>pTemp[x] = (#<uint>pTemp[x]>>1)&0x7f7f7f
next x
pTemp = pImage
for y = 1 to hImage-1
#<uint>pTemp[0] = (#<uint>pTemp[0]>>1)&0x7f7f7f
#<uint>pTemp[wImage] = (#<uint>pTemp[wImage]>>1)&0x7f7f7f
pTemp += oImage
next y
for y = 1 to hImage-1
for x = 1 to wImage-1
p = #<uint>pImage[x-1]
r = p>>16
g = (p>>8)&255
b = p&255
p = #<uint>pImage[x+1]
r2 = p>>16
g2 = (p>>8)&255
b2 = p&255
p = #<uint>pUimage[x]
r3 = p>>16
g3 = (p>>8)&255
b3 = p&255
p = #<uint>pDimage[x]
r4 = p>>16
g4 = (p>>8)&255
b4 = p&255
r = (r+r2+r3+r4)>>2
g = (g+g2+g3+g4)>>2
b = (b+b2+b3+b4)>>2
#<uint>pImage[x] = (r<<16)|(g<<8)|b
next x
pImage += oImage
pUimage += oImage
pDimage += oImage
next y
unlockbuffer
for x = 0 to width
for y = (height - 10) to height
Flame[x,y] = 50 :'set color back to yellow
next y
next x
writetext 25,5,"Press ESC to Exit", BackBuffer
flip
until run = 0
closewindow w
END
sub main(),int
select @CLASS
case @idclosewindow
run = 0
case @idchar
key = @CODE
if (key = 27) then run = 0
endselect
return 0
endsub
sub Rn(low:int,high:int)
' generates a random number between Low and High ..
n = int((high - low + 1) * rnd(1.0) + low)
return n
endsub
Not quite the same but this came out of some experiments I was trying out with drawing fire in IWB.
(Apologies for the cruddy graphic at the bottom but it was only an experiment.)
Kian
http://www.ionicwind.com/forums/index.php?topic=4306.msg33543#msg33543 (http://www.ionicwind.com/forums/index.php?topic=4306.msg33543#msg33543)
Nice Kian. Those blur routines can produce some nice effects. :)
Good try ZD .. :) but I reckon it ought to be possible to get a better representation of flames.
You know .. looking more 'flamelike'. ::)
I don't know how yet - but somehow I don't think the underlying method is the right way to go.
In my try using CB, the size of the fire window could only be small - limited by having to write all those pixels.
In IWB, (apart from your blur method), the window size can be increased up to say 600x300 - but then the 'flames' are a bit crude and the colours not quite right.
I'll put the idea on the back burner - there's always a better way folks say .. ;D
best wishes, :)
Graham