autocam off
color backdrop 0
set ambient light 0
hide mouse
make light 1
position light 1,0,2,0
set light range 1,10000
make light 2
position light 2,0,0,0
set light range 2,10000
position camera 0,0,-2
randomize timer()
sync on
sync rate 0
 
alpha = 30
set camera to image 0,2,512,512
sprite 1,0,0,2
set sprite 1,0,1
set sprite alpha 1,alpha
size sprite 1,800,600
 
createsound("sparkle1",10,8000,3000,500,30,0.01,10,5,0,0,0.05)
createsound("sparkle2",11,6200,5000,300,30,0.01,10,5,0,0,0.05)
createsound("sparkle3",12,4000,5000,800,30,0.01,10,5,0,0,0.05)
createsound("rocket1",4,1600,2000,2000,0.003,0.01,0,0,0,0,10)
createsound("rocket2",5,2000,2500,2000,0.004,0.005,0,0,0,0,10)
createsound("rocket3",7,1800,3500,2000,0.002,0.01,0,0,0,0,10)
createsound("deep explosion",9,30,100,16000,0.00,1.5,.0,0,0,0,100)
 
 
for ob=10000 to 10020
make object box ob,rnd(2)/10.0+0.1,rnd(10)/10.0+0.3,rnd(2)/10.0+0.1
position object ob,rnd(40)/10.0-2,-2+object size y(ob)/2,rnd(40)/10.0-2
set object specular power ob,0
color object ob,rgb(rnd(30),rnd(30),rnd(30))
set object specular ob,rgb(100,100,100)
next ob
global numberoffwks
numberoffwks=8
create_firework()
ink rgb(255,255,255),0
blur=20
for ob=1 to blur
show object ob
next ob
n=blur+1
dim offset(100*numberoffwks)
for clone=100 to 100*numberoffwks step 100
offset(clone)=rnd(100)
next clone
 
do
if rnd(20)=0 then color backdrop rgb(30,30,30) else color backdrop 0
for ob=10000 to 10020
set object specular ob,rgb(rnd(250),rnd(250),rnd(250))
next ob
for clone=0 to 100*numberoffwks step 100
show=n+offset(clone)
if show>100 then dec show,100
hide=n+offset(clone)-blur
if hide>100
  dec hide,100
endif
if hide<1 then inc hide,100
show object show+clone
hide object hide+clone
next clone
inc n
if n>100 then n=1
 
position camera 5*sin(theta#),-2.5,5*cos(theta#)
inc theta#,0.5
point camera 0,0.5,0
 
if rnd(5)=0 and sound playing(4)=0 then play sound 4
if rnd(5)=0 and sound playing(5)=0 then play sound 5
if rnd(5)=0 and sound playing(7)=0 then play sound 7
if rnd(14)=0 and sound playing(9)=0 then play sound 9
if rnd(10)=0 and sound playing(10)=0 then play sound 10
if rnd(10)=0 and sound playing(11)=0 then play sound 11
if rnd(10)=0 and sound playing(12)=0 then play sound 12
text 0,0,str$(screen fps())
sync
loop
 
 
function create_firework
 
bushiness=300
droopiness#=4
roundness=100
density=5
 
create bitmap 2,400,400
set current bitmap 2
cls
for l=1 to bushiness
if rnd(density)=0 then ink rgb(255,255,255),0 else ink 0,0
for d=1 to bushiness
if rnd(density)=0 then dot d,l
next d
next l
get image 1,1,1,bushiness,bushiness,1
set current bitmap 0
delete bitmap 2
 
ob=1
polarity=1
dim x#(100*numberoffwks)
dim y#(100*numberoffwks)
dim z#(100*numberoffwks)
dim r(100*numberoffwks)
dim g(100*numberoffwks)
dim b(100*numberoffwks)
for clone=100 to 100*numberoffwks step 100
x#(clone)=(rnd(30)/10.0)-1.5
y#(clone)=(rnd(30)/10.0)-0.5
z#(clone)=(rnd(30)/10.0)-1.5
r(clone)=(250)
if rnd(1)=0 then g(clone)=(250) else g(clone)=0
if rnd(1)=0 then b(clone)=(250) else b(clone)=0
next clone
for a#=0.01 to 1.0 step 0.01
 
make object sphere ob,(0.05+a#)*1.5,10,10
position object ob,0,-(a#/(droopiness#/0.5)),0
hide object ob
set object transparency ob,5
texture object ob,1
fade object ob,400-(ob*4)
set object specular power ob,0
set object emissive ob,rgb(0,0,255)
set object specular ob,rgb(0,0,255)
 
for clone=100 to 100*numberoffwks step 100
clone object ob+clone,ob
set object emissive ob,rgb(r(clone),g(clone),b(clone))
set object specular ob,rgb(r(clone),g(clone),b(clone))
position object ob+clone,x#(clone),y#(clone)-(a#/(droopiness#/0.5)),z#(clone)
hide object ob+clone
next clone
inc ob
next a#
 
for n#=1.0 to 100.0
xrotate object n#,n#/50.0
next n#
 
endfunction
 
function createsound(name$,soundnumber,frequency#,length#,loudness#,bend#,decay#,vibratospeed#,vibratodepth#,tremelospeed#,tremelodepth#,attack#)
 
outWord as word
dword1 as dword: dword2 as dword: dword3 as dword: dword4 as dword
dword5 as dword: dword6 as dword: dword7 as dword
 
samples=int((length#/1000)*44100)
 
if memblock exist(1) then delete memblock 1
make memblock 1,samples*2+28
 
` write 28 memblock header bytes
dword1=1
dword2=2
dword3=22050
dword4=88200
dword5=4
dword6=16
dword7=0
 
position=0
write memblock dword 1, position, dword1 : inc position,4
write memblock dword 1, position, dword2 : inc position,4
write memblock dword 1, position, dword3 : inc position,4
write memblock dword 1, position, dword4 : inc position,4
write memblock dword 1, position, dword5 : inc position,4
write memblock dword 1, position, dword6 : inc position,4
write memblock dword 1, position, dword7 : inc position,4
 
rem generate and write wave
riseinloudness#=loudness#
for x=1 to samples
  outInteger=int(sin((x/122.5)*(frequency#+vibratodepth#*sin(theta#)))*(loudness#-fallinloudness#-riseinloudness#+tremelodepth#*sin(phi#)))*3.0
  if outInteger <-32767 then outInteger=-32767
  if outInteger>32767 then outInteger=32767
  outWord=outInteger
  inc theta#,vibratospeed#
  inc phi#,tremelospeed#
  dec frequency#,bend#
 
  if fallinloudness#<loudness#
    inc fallinloudness#,decay#
  endif
 
  if riseinloudness#>0
    dec riseinloudness#,attack#
  endif
 
  write memblock word 1, position, outWord : inc position,2
next x
 
if sound exist(soundnumber)=1 then delete sound soundnumber
 
make sound from memblock 999, 1 ` assumes you won't need sound number 999!
clone sound soundnumber, 999
delete sound 999
 
` memblock no longer required
delete memblock 1
 
endfunction