
if not material then
 material = "gamepiece"
end

gCreationRange = GUI_Slider(
   4.90,
   "Blur Generation Range",
   0,100);

gEmitSpeed = GUI_Slider(
   69.20,
      "Emitter Speed",
      0,200);

gScale = GUI_Slider(
   1.07,
      "Scale",
      0,3.0);

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

gTextureName = GUI_PickTexture(material,"Particle Texture");

gMaxParticles = GUI_Slider(
   100.00,
      "Max Particles",
      0,100);

if iScale then
 mScale = iScale;
end
	  
pOffset = Allocate(2) ; -- Allocate a Vec2 velocity member
pAge = Allocate(1) ; -- Allocate a TReal age member
SetTexture(gTextureName);
SetBlendMode(gBlendMode);
SetNumParticles(gMaxParticles);

pOffset:Init( fRange( Vec2(-1,-1), Vec2(1,1) )*gCreationRange );

-- Start scale at 0.5
pScale:Init( mScale );

-- Start age as 0 milliseconds
pAge:Init(0);

-- ------------------------------------------------------------
-- Particle Parameter Animation Functions
--
pPosition:Anim( pOffset +dLocus);

-- Fade (using age) from white to yellow to black. Assumes
-- the first parameter is a number of elapsed milliseconds,
-- though can work to linearly interpolate using first 
-- scalar parameter between any value types.
pColor:Anim( 
   fFade( pAge,
      Color(0,0,1,0),100,
      Color(0,0,1,0.15),900,
      Color(0,0,1,0) ) -- to final color
   );

-- Age the particle using age function
pAge:Anim( pAge+fAge() );

-- General Anim functions
-- Expire particles over 700 ms old
Anim( fExpire( fGreater(pAge,1000) ) );

-- A function to run as we're executing
-- seconds - how many seconds have elapsed

function setPcolorAnim(alpha)

pColor:Anim( 
   fFade( pAge,
      Color(0,0,1,0),100,
      Color(0,0,1,alpha),900,
      Color(0,0,1,0) ) -- to final color
   );
end

function Update(seconds)
   CreateParticles( seconds * gEmitSpeed );
end

