Post by Tom Mulgrew on May 14, 2005 2:33:38 GMT -5
Thought this looked kinda cool..
const xFireSize = 128, yFireSize = 64
const xScrollSize = 64, yScrollSize = 32
const hot = 5, gradientSize = 256 * (hot + 2)
const xFactor = xFireSize / xScrollSize, yFactor = yFireSize / yScrollSize
const ambient = 255, top = 200, sides = 20
dim fire (yFireSize - 1)(xFireSize - 1)
dim ¤t(),&below()
dim scroller(xScrollSize + 1)(yScrollSize + 1)
dim gradient (gradientSize - 1)
dim x, y, xScreen, yScreen
dim xScroller, sum, i, offset#
dim line$, above$, below$, c1$, c2$, c3$, a#, speed#, angSpeed#
const blanks$ = " "
Scroller:
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " ************** "
data " ************** "
data " ** "
data " ** **** ** ** "
data " ** ****** ******** "
data " ** *** *** ** ** ** "
data " ** ** ** ** ** ** "
data " ** ** ** ** ** ** "
data " ** *** *** ** ** ** "
data " ** ****** ** ** ** "
data " ** **** ** ** ** "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
data " "
reset Scroller
for y = 1 to yScrollSize
read line$
for x = 1 to xScrollSize
scroller(x)(y) = mid$ (line$, x, 1) <> " "
next
next
for i = 0 to gradientSize - 1
gradient (i) = i * 255.0 / gradientSize
next
' Setup OpenGL
glMatrixMode (GL_PROJECTION) ' Use a 2D projection (2D mode)
glLoadIdentity ()
gluOrtho2D (0, 1, 0, 1)
glMatrixMode (GL_MODELVIEW)
' Setup an OpenGL texture.
' We will copy our image into this texture and draw it as a quad
dim tex
glEnable (GL_TEXTURE_2D)
tex = glGenTexture ()
glBindTexture (GL_TEXTURE_2D, tex)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
gosub NewSpeed
while true
xScroller = offset# + sin (a#) * xFireSize * .075
' Animate flames
for y = 0 to yFireSize - 2
¤t = &fire (y)
&below = &fire (y+1)
for x = 0 to xFireSize - 1
current (x) = gradient (below ((x-1)%xFireSize) + below(x)*hot + below ((x+1)%xFireSize))
next
next
for x = 0 to xFireSize - 1
below(x) = rnd()%ambient
next
for y = 1 to yScrollSize
for x =1 to xScrollSize
if scroller(x)(y) then
if not scroller (x)(y-1) then
xScreen = ((x-1) * xFactor + xScroller) % xFireSize
yScreen = y * yFactor
for i = 0 to xFactor - 1
fire(yScreen)((xScreen+i)%xFireSize) = rnd () % top
next
endif
if not scroller (x)(y+1) then
xScreen = ((x-1) * xFactor + xScroller) % xFireSize
yScreen = y * yFactor + yFactor - 1
for i = 0 to xFactor - 1
fire(yScreen)((xScreen+i) % xFireSize) = 0
next
endif
if not scroller (x-1)(y) then
xScreen = ((x-1) * xFactor + xScroller) % xFireSize
yScreen = y * yFactor
for i = 0 to yFactor - 1
fire (yScreen + i)(xScreen) = 0
fire (yScreen + i)((xScreen - 1) % xFireSize) = rnd () % sides
next
endif
if not scroller (x+1)(y) then
xScreen = ((x-1) * xFactor + xFactor - 1 + xScroller) % xFireSize
yScreen = y * yFactor
for i = 0 to yFactor - 1
fire (yScreen + i)(xScreen) = 0
fire (yScreen + i)((xScreen + 1) % xFireSize) = rnd () % sides
next
endif
endif
next
next
' Load array into current OpenGL texture
' We will use GL_LUMINANCE, to create a luminance texture.
' This is a texture of a single colour, but varying brightness (luminance).
' We use GL_UNSIGNED_BYTE, to instruct OpenGL to treat each element as a byte.
' So 0 is the minimum brightness, and 255 is the maximum,
glTexImage2D (GL_TEXTURE_2D, 0, 1, xFireSize, yFireSize, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, fire)
' Draw texture.
glClearColor (0.3, 0, 0, 1)
glDisable (GL_DEPTH_TEST)
glEnable (GL_TEXTURE_2D)
glEnable (GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE)
glClear (GL_COLOR_BUFFER_BIT)
glLoadIdentity ()
for i = 1 to 2
glBegin (GL_QUADS)
glColor3f (.7, 1, 1)
glTexCoord2f (0, 1): glVertex2f (0, 0)
glTexCoord2f (1, 1): glVertex2f (1, 0)
glColor3f (1, 1, .4)
glTexCoord2f (1, 0): glVertex2f (1, 1)
glTexCoord2f (0, 0): glVertex2f (0, 1)
glEnd ()
glTranslatef (-.5, -1, 0)
glScalef (1.5, 2, 1)
next
' Show texture
SwapBuffers ()
a# = a# + angSpeed#
offset# = offset# + speed#
if rnd () % 400 = 0 then
gosub NewSpeed
endif
wend
end
NewSpeed:
angSpeed# = (rnd () % 2001 - 1000) / 1000.0 * 0.1
speed# = (rnd () % 2001 - 1000) / 1000.0 * 0.75
return