include "..\GDIWindow\window.inc"
Window "Big Bang", 640, 480, 2
sys xscreen =640, yscreen =480, i, sz
'Font 12,24,0,"courier"
sys anzahl=1000

single xmitte = xscreen/2, ymitte = yscreen/2


'=============
class Particle
'=============
  
  single x,y,xv,yv,diam
  sys    sz
  byte   red,green,blue,alpha
  sys    pob
  string sbuf

method index(sys i)
  pob=strptr(sbuf)+i*sizeof particle
end method

method populate(sys e)
  sys i,b
  sbuf=nuls e*sizeof particle
  pob=strptr sbuf
  for i=0 to <e
    rebirth
    pob+=sizeof particle
  next
end method

method rebirth()
  single r,a
  @this = pob
  x     = xmitte
  y     = ymitte
  a     = rand(1,628)*.01
  r     = rand(20,100)*.1
  xv    = r*cos(a)
  yv    = r*sin(a)
  diam  = rand(10,25)*.1
  red   = rand(40,250)
  green = rand(40,250)
  blue  = rand(20,250)
end method

method outside() as sys
  @this=pob
  if x<0 or y<0 or x>=xscreen or y>=yscreen then return 1
end method

method move()
  @this=pob
  single adist,a
  adist=hypot(xmitte-x,ymitte-y)
  a=adist*.002+.1
  x += xv*a
  y += yv*a
  sz=adist*diam*.015+2
end method

method show()
  @this=pob
  Oval x, y, sz, sz, red, green, blue
end method

end class



particle pa
pa.populate anzahl

'PlayWav "..\GDIWindow\cosmobumm.wav",0,1


While Key(27)=0
ClsColor 2,2,2
for i=0 to <anzahl
  pa.index i
  pa.move
  if pa.outside then
    pa.rebirth
  else
    pa.show
  end if
next
'
Events
FlipBuffer
WaitFPS 80
Wend
WinEnd

