Code: Select all
'PRESS LEFT MOUSE BUTTON TO MAKE SPARKS. In this code only 1000 sparks can be made.
'some useful defines
Const Pi = 4 * Atn(1)
Dim Shared As Double TwoPi = 8 * Atn(1)
Dim Shared As Double RtoD = 180 / Pi ' radians * RtoD = degrees
Dim Shared As Double DtoR = Pi / 180 ' degrees * DtoR = radians
screenres 640,480,32
type SPARK
as single px
as single py
as single vx
as single vy
as ulong c
as integer a
end type
dim shared as SPARK sparks(0 to 1000)
dim shared as integer total
sub drawSparks()
dim as single dx,dy,angle,rr
dim as ulong r,g,b,cc
screenlock
cls
if total<>0 then
for i as integer = 0 to total-1
cc = sparks(i).c
'fade the color by width
r = cc shr 16 and 255
g = cc shr 8 and 255
b = cc and 255
r = r\(sparks(i).a\10)
g = g\(sparks(i).a\10)
b = b\(sparks(i).a\10)
if r < 0 then r = 0
if g < 0 then g = 0
if b < 0 then b = 0
'random sparks within circle radius rr
for j as integer = 0 to 29
rr = int(rnd(1)*sparks(i).a) 'gets wider each time
angle = int(Rnd(1)*360)*DtoR
dx = cos(angle)*rr
dy = sin(angle)*rr
circle(sparks(i).px+dx,sparks(i).py+dy),2,rgb(r,g,b),,,,f
next j
sparks(i).px = sparks(i).px + sparks(i).vx
sparks(i).py = sparks(i).py + sparks(i).vy
sparks(i).vy = sparks(i).vy + 0.1 'gravity
sparks(i).a = sparks(i).a + 1 'increase width
next i
end if
screenunlock
end sub
dim as integer mx,my,mb
do
getmouse mx,my,,mb
if mb = 1 then
sparks(total).a = 10
sparks(total).px = mx
sparks(total).py = my
sparks(total).vx = int(rnd(1)*5)-2
sparks(total).vy = -1
sparks(total).c = rgb(int(rnd(1)*256),int(rnd(1)*256),int(rnd(1)*256))
if total < 1000 then
total = total + 1
end if
end if
drawSparks()
sleep 2
loop until multikey(&H01)