Ive been coding in Blitz for about a year now, but only just got round to having a go at doing particle effects. Theres some pretty amazing stuff on this site. Makes me feel kinda dumb. Anyway heres my attempt. Its kinda like a slinky thing that follows the mouse around.
Graphics 1024, 768
Global particles = CreateImage(GraphicsWidth(), GraphicsHeight())
Global count, oldtime, fps ;for fps
Global mode
Global col_timer, col_change
SeedRnd MilliSecs()
Type particle
Field x#, y#, id, ang#, spd
;For colour effects
Field r, g, b; rf, gf, bf
;for circle particles. start size and expand rate
Field rad#, expand#, expand_max
End Type
Global rf =5
Global gf =5
Global bf =5
SetBuffer BackBuffer()
While Not KeyHit(1)
Cls
If mode = 0
NEW_BURST(MouseX(), MouseY(),10)
CIRCLE_PARTICLES(0)
Text 460, 0, "MOVE THE MOUSE"
If mousehit(1) Then mode = 1
COL_CHANGE()
Else
If Rand(0, 2) = 0 Then NEW_BURST(Rand(0, 1023), Rand(0, 768),Rand(10, 30))
CIRCLE_PARTICLES(1)
t=t+ 1
If t > 100
mode = 0
t=0
EndIf
EndIf
DrawImage particles, 0, 0
FPS()
Flip
Wend
;---------------------------;
Function NEW_BURST(x_pos, y_pos, parts)
a_step# = Float(360)/parts
test = a_step#
For i = 1 To parts
p.particle = New particle
p\x = x_pos
p\y = y_pos
p\ang# = angle#
angle# = angle# + a_step#
p\expand = 0.1
p\rad = 0.1
p\expand_max = 10
p\spd = 1
p\rad = 0.1
p\expand_max = 30
p\spd = 1
If mode = 1 Then p\expand = Float(Rand(1, 5))/10
p\r = 255
p\g = 255
p\b = 255
Next
End Function
;---------------------------;
Function CIRCLE_PARTICLES(fill)
SetBuffer ImageBuffer(particles)
Cls
LockBuffer
For p.particle = Each particle
If p\x < -rad Or p\x >= GraphicsWidth()+rad Or p\y < -rad Or p\y >= GraphicsWidth()+rad
Delete p.particle
Else
If p\rad# < p\expand_max Then p\rad# = p\rad# + p\expand#
If p\r >= rf Then p\r = p\r - rf
If p\g >= gf Then p\g = p\g - gf
If p\b >= bf Then p\b = p\b - bf
col = (p\r Shl 16) + (p\g Shl 8) + p\b
p\x = p\x +Cos(p\ang)*p\spd
p\y = p\y +Sin(p\ang)*p\spd
If fill = 0
CIRCLE(p\x, p\y, p\rad, col)
Else
F_CIRCLE(p\x, p\y, p\rad, col)
EndIf
If col <= (rf Shl 16)+(gf Shl 8)+bf Then Delete p.particle
EndIf
Next
UnlockBuffer
SetBuffer BackBuffer()
End Function
;---------------------------;
Function CIRCLE(cx, cy, rad, col)
inc# = Float(360/(rad*Pi*2))
steps = 360/inc#
For i = 0 To steps
x = (cx - rad * Cos(deg#))
y = (cy - rad * Sin(deg#))
If x >= 0 And x < GraphicsWidth() And y >= 0 And y < GraphicsHeight()
WritePixelFast x, y, col
EndIf
deg# = deg# + inc#
Next
End Function
;---------------------------;
Function F_CIRCLE(cx, cy, rad, col)
inc# = Float(360/(rad*Pi*2))
steps = 90/inc#
For i = 0 To steps
x1 = (cx - rad * Cos(deg#))
y1 = (cy - rad * Sin(deg#))
x2 = cx+cx-x1
y2 = cy+cy-y1
If x1 < 0 Then x1 = 0
If x2 > 1023 Then x2 = 1023
If y1 < 0 Then y1 = 0
If y1 > 767 Then y1 = 767
If y2 < 0 Then y2 = 0
If y2 > 767 Then y2 = 767
For x = x1 To x2
WritePixelFast x, y1, col
Next
For x = x1 To x2
WritePixelFast x, y2, col
Next
deg# = deg# + inc#
Next
End Function
;---------------------------;
Function FPS()
Text 0, 0, "FPS: "+fps
time = MilliSecs() - oldtime
count = count + 1
If time >= 1000
fps = count
count = 0
oldtime=MilliSecs()
EndIf
End Function
;---------------------------;
Function COL_CHANGE()
col_timer = col_timer + 1
If col_timer = 10
col_timer = 0
If col_change = 0
rf = rf - 1
If rf = 0
col_change = col_change + 1
EndIf
Else If col_change = 1
rf = rf + 1
gf = gf - 1
If gf = 0
col_change = col_change + 1
EndIf
Else If col_change = 2
bf = bf - 1
gf = gf + 1
If bf = 0
col_change = col_change + 1
EndIf
Else If col_change = 3
rf = rf - 1
gf = gf - 1
bf = bf + 1
If rf = 0
col_change = col_change + 1
EndIf
Else If col_change = 4
rf = rf + 1
bf = bf - 1
If bf = 0
col_change = col_change + 1
EndIf
Else If col_change = 5
bf = bf + 1
gf = gf + 1
If bf = 5
col_change = 0
EndIf
EndIf
EndIf
End Function