-- ================================================================================
gTexture = GUI_PickTexture("sparkle","Particle Texture");
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},
   }
);
gNumParticles = GUI_Slider(
   120.00,
   "Max Number of Particles",
   0,1000);
gPPS = GUI_Slider(
   40.00,
   "Particles Per Second",
   0,200);
gParticleLife = GUI_Slider(
   400.00,
   "Particle Life",
   0,3000);
gInitColor = GUI_ColorPick(
223,55,60,255,
   "Initial Color");
gInitPosX = GUI_Slider(
   44.00,
   "Initial X Offset",
   0,100);
gInitPosY = GUI_Slider(
   22.40,
   "Initial Y Offset",
   0,100);
gInitVelX = GUI_Slider(
   0.50,
   "Initial X Velocity",
   -10,10);
gInitVelY = GUI_Slider(
   1.02,
   "Initial Y Velocity",
   -10,10);
gInitWeight = GUI_Slider(
   0.04,
   "Initial Weight",
   -10,10);
gInitRot = GUI_Slider(
   0,
   "Initial Rotation",
   0,6.28);
gInitSize = GUI_Slider(
   0.08,
   "Initial Size",
   0.01,100);
gInitSizeRange = GUI_Slider(
   0.00,
   "Init Size Variation",
   0,100);
gVelocityOverTime = GUI_Graph(
   {
      Vec2(0.00,0.00),1000,
      Vec2(-0.00,0.00),2,
      Vec2(-0.00,0.00)
   },
   Vec2(-5.00,-5.00),
   Vec2(5.00,5.00),
   {
      {0.00,0.00,time=0.00},
      {nil,0.00,time=1000.00},
      {-0.00,nil,time=1002.43}
   },
   "Velocity Over Time");
gScaleOverTime = GUI_Graph(
   {
      1.00,1000,
      0.00
   },
   0.00,
   10.00,
   {
      {1.00,time=0.00},
      {0.00,time=1000.00}
   },
   "Scale Over Time");
gColorOverTime = GUI_Graph(
   {
      Color(0.85,0.11,0.24,1.00),77,
      Color(0.85,0.11,0.24,0.66),96,
      Color(0.80,0.79,0.15,0.98),107,
      Color(0.80,0.79,0.15,0.43),4,
      Color(0.32,0.58,0.64,0.98),175,
      Color(0.32,0.58,0.64,0.52),32,
      Color(0.32,0.58,0.64,0.98),67,
      Color(0.32,0.58,0.64,0.01),105,
      Color(0.32,0.58,0.64,0.86),128,
      Color(1.00,1.00,1.00,0.0)
   },
   Color(0,0,0,0),
   Color(1,1,1,1),
   {
      {0.85,0.11,0.24,1.00,time=0.00},
      {0.85,0.11,0.24,0.66,time=77.94},
      {0.80,0.79,0.15,0.98,time=174.22},
      {0.80,0.79,0.15,0.43,time=281.58},
      {0.32,0.58,0.64,0.98,time=285.74},
      {0.32,0.58,0.64,0.52,time=460.99},
      {0.32,0.58,0.64,0.98,time=493.64},
      {0.32,0.58,0.64,0.01,time=560.83},
      {0.32,0.58,0.64,0.86,time=666.81},
      {1.00,1.00,1.00,0.00,time=795.47},
   },
   "Color Over Time");
-- ================================================================================
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(-gInitPosX,-gInitPosY),Vec2(gInitPosX,gInitPosY)) );
pScale:Init( fRange(gInitSize,gInitSize+gInitSizeRange) );
pColor:Init(gInitColor);
pAge:Init(0);
pVelocity:Init(fRange(Vec2(-gInitVelX,-gInitVelY),Vec2(gInitVelX,gInitVelY)));
pRotation:Init(gInitRot);
pUp:Init(f2dRotation(pRotation));
-- ================================================================================
pAge:Anim( pAge+fAge() );
pVelocity:Anim(Vec2(0,gInitWeight)+pVelocity+fFade(pAge,toparams(gVelocityOverTime)));
pPosition:Anim(pPosition+pVelocity);
pColor:Anim(fFade(pAge,toparams(gColorOverTime)));
--pScale:Anim(pScale+fFade(pAge,toparams(gScaleOverTime)));
Anim( fExpire( fGreater(pAge,gParticleLife) ) );
-- ================================================================================

gEvolveParticles = true;
function Update(seconds)
   if(gEvolveParticles) then
	  CreateParticles( seconds * gPPS );
   end
end
