Post by Scott Brosious on Jul 9, 2004 5:33:20 GMT -5
const width = 200, height = 200
const nop = 250 ' Number of particles
const xcntr = 100 ' XCenter
const ycntr = 100 ' YCenter
const grav# = .01
const dis = 10
dim xbuffer#(dis)(nop)
dim ybuffer#(dis)(nop)
dim intensity#(dis)(nop)
dim lite#(nop)
dim a
dim h,i
dim t1,t2 ' Starting and ending time variables
dim choice
dim speed(nop)
dim time(nop) ' Timer
dim xpos#(nop) ' Xposition
dim ypos#(nop) ' Yposition
dim xvel#(nop) ' X velocity. This is added to xpos# each time
dim yvel#(nop) ' Y velocity. This is added to ypos# each time
dim ang#(nop) ' Angles
dim st(nop) ' Start time
dim et(nop) ' End time
dim mt(nop) ' Time to move
dim alpha# ' Star transparency. 0 = fully transparent (invisible). 1 = fully solid. 0.5 = half transparent e.t.c.
dim red(nop) ' Red Component
dim green(nop) ' Green Component
dim blue(nop) ' Blue Component
for i = 1 to nop
gosub Inittime
st(i) = t1 ' Start time
et(i) = t2 ' End time
gosub Angles
ang#(i) = a ' Put angle into array
xvel#(i)= cosd(ang#(i))
yvel#(i)= sind(ang#(i))
xpos#(i)= xcntr
ypos#(i)= ycntr
xbuffer#(dis)(i) = xpos#(i)
ybuffer#(dis)(i) = ypos#(i)
next
for i = 1 to nop
choice = int(rnd() % 7) + 1
if choice = 1 then red(i) = 1: green(i) = 0: blue(i) = 0: endif
if choice = 2 then red(i) = 0: green(i) = 1: blue(i) = 0: endif
if choice = 3 then red(i) = 0: green(i) = 0: blue(i) = 1: endif
if choice = 4 then red(i) = 1: green(i) = 1: blue(i) = 0: endif
if choice = 5 then red(i) = 0: green(i) = 1: blue(i) = 1: endif
if choice = 6 then red(i) = 1: green(i) = 0: blue(i) = 1: endif
if choice = 7 then red(i) = 1: green(i) = 1: blue(i) = 1: endif
next
' Set 2D mode
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0, width, 0, height, -1, 1)
glMatrixMode (GL_MODELVIEW)
glDisable (GL_DEPTH_TEST)
' Translucency, Blending
glBlendFunc(GL_SRC_ALPHA,GL_ONE)
glEnable(GL_BLEND)
glEnable (GL_LINE_SMOOTH)
glLineWidth (2)
while true
for i = 1 to nop
if time(i) > st(i) then
mt(i) = mt(i) + 1
if mt(i) > et(i) then gosub Refresh :endif
if mt(i) > 1 then speed(i) = 1 endif
xpos# (i) = xpos# (i) + xvel# (i) * speed(i)
ypos# (i) = ypos# (i) + yvel# (i) * speed(i)
xbuffer#(dis)(i) = xpos#(i)
ybuffer#(dis)(i) = ypos#(i)
' Apply gravity to y velocity
yvel# (i) = yvel# (i) - grav#
endif
if et(i) > 0 then
alpha# = mt(i) * 1.0 / et(i)
' Note:
' Alpha ranges from 0, when the star is at the start position (mt(i) = 0)
' to 1, when the star is at the end position (mt(i) = et(i))
' We want alpha to be 1 (fully bright) at the start position, and 0 (fully dim)
' at the end position, so we need to reverse this.
alpha# = 1 - alpha#
else
alpha# = 1
endif
intensity#(dis)(i) = alpha#
next
glClear (GL_COLOR_BUFFER_BIT)
glBegin (GL_LINES)
for i = 1 to nop
for h = 1 to dis - 1
glColor4f ( red(i), green(i), blue(i), intensity#(h)(i))
glVertex2f (xbuffer#(h)(i),ybuffer#(h)(i))
glVertex2f (xbuffer#(h+1)(i),ybuffer#(h+1)(i))
next
next
glEnd()
' Display output
SwapBuffers ()
for i = 1 to nop
time(i) = time(i) + 1
next
for i = 1 to nop
for h = 1 to dis-1
xbuffer#(h)(i) = xbuffer#(h+1)(i)
ybuffer#(h)(i) = ybuffer#(h+1)(i)
intensity#(h)(i) = intensity#(h+1)(i) - .1
next
next
wend
ReFresh:
gosub InitTime
st(i) = t1
et(i) = t2
mt(i) = 0
time(i) = 0
speed(i) = 0
gosub Angles
ang#(i) = a
return
InitTime:
t1 = int(rnd() % 50) ' When to start
t2 = int(rnd() % 150) ' When to end
return
Angles:
a = int(rnd() % 360)
xvel#(i)= cosd(ang#(i))
yvel#(i)= sind(ang#(i))
xpos#(i)= xcntr
ypos#(i)= ycntr
return
const nop = 250 ' Number of particles
const xcntr = 100 ' XCenter
const ycntr = 100 ' YCenter
const grav# = .01
const dis = 10
dim xbuffer#(dis)(nop)
dim ybuffer#(dis)(nop)
dim intensity#(dis)(nop)
dim lite#(nop)
dim a
dim h,i
dim t1,t2 ' Starting and ending time variables
dim choice
dim speed(nop)
dim time(nop) ' Timer
dim xpos#(nop) ' Xposition
dim ypos#(nop) ' Yposition
dim xvel#(nop) ' X velocity. This is added to xpos# each time
dim yvel#(nop) ' Y velocity. This is added to ypos# each time
dim ang#(nop) ' Angles
dim st(nop) ' Start time
dim et(nop) ' End time
dim mt(nop) ' Time to move
dim alpha# ' Star transparency. 0 = fully transparent (invisible). 1 = fully solid. 0.5 = half transparent e.t.c.
dim red(nop) ' Red Component
dim green(nop) ' Green Component
dim blue(nop) ' Blue Component
for i = 1 to nop
gosub Inittime
st(i) = t1 ' Start time
et(i) = t2 ' End time
gosub Angles
ang#(i) = a ' Put angle into array
xvel#(i)= cosd(ang#(i))
yvel#(i)= sind(ang#(i))
xpos#(i)= xcntr
ypos#(i)= ycntr
xbuffer#(dis)(i) = xpos#(i)
ybuffer#(dis)(i) = ypos#(i)
next
for i = 1 to nop
choice = int(rnd() % 7) + 1
if choice = 1 then red(i) = 1: green(i) = 0: blue(i) = 0: endif
if choice = 2 then red(i) = 0: green(i) = 1: blue(i) = 0: endif
if choice = 3 then red(i) = 0: green(i) = 0: blue(i) = 1: endif
if choice = 4 then red(i) = 1: green(i) = 1: blue(i) = 0: endif
if choice = 5 then red(i) = 0: green(i) = 1: blue(i) = 1: endif
if choice = 6 then red(i) = 1: green(i) = 0: blue(i) = 1: endif
if choice = 7 then red(i) = 1: green(i) = 1: blue(i) = 1: endif
next
' Set 2D mode
glMatrixMode (GL_PROJECTION)
glLoadIdentity ()
glOrtho (0, width, 0, height, -1, 1)
glMatrixMode (GL_MODELVIEW)
glDisable (GL_DEPTH_TEST)
' Translucency, Blending
glBlendFunc(GL_SRC_ALPHA,GL_ONE)
glEnable(GL_BLEND)
glEnable (GL_LINE_SMOOTH)
glLineWidth (2)
while true
for i = 1 to nop
if time(i) > st(i) then
mt(i) = mt(i) + 1
if mt(i) > et(i) then gosub Refresh :endif
if mt(i) > 1 then speed(i) = 1 endif
xpos# (i) = xpos# (i) + xvel# (i) * speed(i)
ypos# (i) = ypos# (i) + yvel# (i) * speed(i)
xbuffer#(dis)(i) = xpos#(i)
ybuffer#(dis)(i) = ypos#(i)
' Apply gravity to y velocity
yvel# (i) = yvel# (i) - grav#
endif
if et(i) > 0 then
alpha# = mt(i) * 1.0 / et(i)
' Note:
' Alpha ranges from 0, when the star is at the start position (mt(i) = 0)
' to 1, when the star is at the end position (mt(i) = et(i))
' We want alpha to be 1 (fully bright) at the start position, and 0 (fully dim)
' at the end position, so we need to reverse this.
alpha# = 1 - alpha#
else
alpha# = 1
endif
intensity#(dis)(i) = alpha#
next
glClear (GL_COLOR_BUFFER_BIT)
glBegin (GL_LINES)
for i = 1 to nop
for h = 1 to dis - 1
glColor4f ( red(i), green(i), blue(i), intensity#(h)(i))
glVertex2f (xbuffer#(h)(i),ybuffer#(h)(i))
glVertex2f (xbuffer#(h+1)(i),ybuffer#(h+1)(i))
next
next
glEnd()
' Display output
SwapBuffers ()
for i = 1 to nop
time(i) = time(i) + 1
next
for i = 1 to nop
for h = 1 to dis-1
xbuffer#(h)(i) = xbuffer#(h+1)(i)
ybuffer#(h)(i) = ybuffer#(h+1)(i)
intensity#(h)(i) = intensity#(h+1)(i) - .1
next
next
wend
ReFresh:
gosub InitTime
st(i) = t1
et(i) = t2
mt(i) = 0
time(i) = 0
speed(i) = 0
gosub Angles
ang#(i) = a
return
InitTime:
t1 = int(rnd() % 50) ' When to start
t2 = int(rnd() % 150) ' When to end
return
Angles:
a = int(rnd() % 360)
xvel#(i)= cosd(ang#(i))
yvel#(i)= sind(ang#(i))
xpos#(i)= xcntr
ypos#(i)= ycntr
return