34

My first GL program, a cool yet slow fire routine using a simple method I read about long ago.

`// --------------------------------- //`

// Project: untitled

// Start: Wednesday, December 31, 1969

// IDE Version: 8.078

// c = (a*16777216)+(b*65536)+(g*256)+r

SETSCREEN 640, 480, 0

GLOBAL flame = 4.14

GLOBAL fire[]

DIM fire[320][240]

LOCAL r

REPEAT

FOR y = 0 TO 239

FOR x = 0 TO 319

fire[x][y] = newValue(x, y)

SETPIXEL x, y, fire[x][y]

NEXT

NEXT

FOR x = 0 TO 319

r = RND(255)

fire[x][238] = RGB(r,0,r)

SETPIXEL x, 238, fire[x][238]

NEXT

SHOWSCREEN

UNTIL KEY(28) = 1

END

FUNCTION newValue:x, y

LOCAL r,g,b,c,c1,c2,c3,c4,r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4

c1 = getColor(x, y+1)

r1 = GetRValue(c1)

g1 = GetGValue(c1)

b1 = GetBValue(c1)

c2 = getColor(x-1, y+1)

r2 = GetRValue(c2)

g2 = GetGValue(c2)

b2 = GetBValue(c2)

c3 = getColor(x+1, y+1)

r3 = GetRValue(c3)

g3 = GetGValue(c3)

b3 = GetBValue(c3)

c4 = getColor(x, y+2)

r4 = GetRValue(c4)

g4 = GetGValue(c4)

b4 = GetBValue(c4)

r = (r1+r2+r3+r4)/4.14

g = (g1+g2+g3+g4)/4.14

b = (b1+b2+b3+b4)/4.14

c = RGB(r, g, b)

RETURN c

ENDFUNCTION

FUNCTION getColor:x, y

IF x >= 0 AND x < 320 AND y >= 0 AND y < 239 THEN RETURN fire[x][y]

RETURN 0

ENDFUNCTION

FUNCTION GetRValue: Color

RETURN bAND(Color,255)

ENDFUNCTION

FUNCTION GetGValue: Color

RETURN (Color - (INTEGER(Color / 65536)*65536+bAND(Color,255))) / 256

ENDFUNCTION

FUNCTION GetBValue: Color

RETURN INTEGER(Color / 65536)

ENDFUNCTION

I did notice the functions supplied with the GLBasic examples for retrieving color components were incorrect. It appeared they assumed RGB but I guess it's store as BGR.