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

  method rebirth()
  ================
  'create particle characteristics with random values
  single r,a
  x     = xmitte           'x position
  y     = ymitte           'y position
  a     = rand(1,628)*.01  'travel angle
  r     = rand(20,100)*.1  'radius
  xv    = r*cos(a)         'x velocity
  yv    = r*sin(a)         'y velocity
  diam  = rand(10,25)*.1   'diameter
  red   = rand(40,250)     'color component red
  green = rand(40,250)     'color component green
  blue  = rand(20,250)     'color component blue
  end method

  method outside() as sys
  =======================
  if x<0 or y<0 or x>=xscreen or y>=yscreen
    return 1
  endif
  end method

  method move()
  =============
  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()
  =============
  Oval x, y, sz, sz, red, green, blue
  end method

end class

'==============
class Particles
'==============
  
  particle*part
  string sbuf
  int qty

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

  method populate(sys e)
  ======================
  sys i
  sbuf=nuls e*sizeof particle
  @part=strptr sbuf
  for i=0 to <e
    part.rebirth
    @part+=sizeof particle 'stride
  next
  qty=e
  end method

  method action()
  ===============
  sys i
  @part=strptr sbuf
  for i=0 to <qty
    part.move
    if part.outside then
      part.rebirth
    else
      part.show
    end if
    @part+=sizeof particle 'stride
  next
  end method

end class



particles pa
pa.populate anzahl

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


While Key(27)=0
  ClsColor 2,2,40
  pa.action
  '
  Events
  FlipBuffer
  WaitFPS 120
Wend
WinEnd

