
gScale = GUI_Graph(
   {
      0.00,1486,
      0.00,1018,
      0.40
   },
   0.00,
   2.0,
   {
      {0.00,time=0.00},
      {0.00,time=1485.63},
      {0.40,time=2503.66}
   },
   "Scale Anim");

gStartScale = GUI_Slider(
   0.10,
   "Start Scale",
   0.1,0.75);

gStartPos = GUI_Slider(
   0.00,
   "Start Range",
   0,200);

gRotation = GUI_Slider(
   3.35,
   "Initial Rotation",
   0,6.28);

gColor = GUI_Graph(
   {
      Color(1.00,0.85,0.01,0.30),501,
      Color(0.04,0.95,1.00,0.40),158,
      Color(0.57,0.98,1.00,0.30),87,
      Color(0.84,0.84,1.00,0.0)
   },
   Color(0,0,0,0),
   Color(1,1,1,1),
   {
      {1.00,0.85,0.01,0.30,time=0.00},
      {0.04,0.95,1.00,0.40,time=501.35},
      {0.57,0.98,1.00,0.30,time=659.43},
      {0.84,0.84,1.00,0.00,time=746.79},
   },
   "Color");

gPLife = GUI_Slider(
   1000.00,
   "Max Life",
   0,10000);

gPPS = GUI_Slider(
   99.90,
   "Particles Per Second",
   0,100);

gNumParticles = GUI_Slider(
   10.00,
   "Max Particles",
   0,100);

gBlendMode = GUI_Select(
   kBlendAdditiveAlpha,
   "Blend Mode",
   {
      { description="Normal", value=kBlendNormal},
      { description="Additive Alpha", value=kBlendAdditiveAlpha},
      { description="Multiplicative", value=kBlendMultiplicative},
      { description="Subtractive", value=kBlendSubtractive},
      { description="Opaque", value=kBlendOpaque},

   }
);

gTexture = GUI_PickTexture("fx/sparkle","Texture");

gTimeOut = GUI_Slider(
   1.00,
   "Time Out:",
   1.0, 10.0);

pAge = Allocate(1); 
pVelocity = Allocate(2);
pRotation = Allocate(1);


SetTexture(gTexture);
SetBlendMode(gBlendMode);
SetNumParticles(gNumParticles);

if not dLocus then
   dLocus= Vec2(0,0) ; 
end

pPosition:Init( dLocus+fRange(Vec2(-gStartPos,0),Vec2(gStartPos,0)) );
pScale:Init( fRange(0.1,0.2) );
pColor:Init(Color(1,1,1,1));
pAge:Init(0);
pVelocity:Init(fRange(Vec2(1.0,1.0),Vec2(-1.0,-1.0)));
--pRotation:Init(fRange(0.0,6.28));
--pUp:Init(f2dRotation(pRotation));

pAge:Anim( pAge+fAge() );
pVelocity:Anim(pVelocity+fFade(pAge,Vec2(0,0),0,Vec2(0,0)));
pPosition:Anim(pPosition+pVelocity);
pColor:Anim(fFade(pAge,toparams(gColor)));
--pScale:Anim(pScale+fFade(pAge,toparams(gScale)));

Anim( fExpire( fGreater(pAge,gPLife) ) );

-- expire after N seconds
expired = NewTimeout(gTimeOut);

function Update(seconds)
   DebugOut("fx sparks seconds = "..seconds);
   if not expired(seconds) then
      CreateParticles( seconds * gPPS );
   elseif GetParticleCount() <= 0 then
      Done();
   end
end
