mMaxAlpha = GUI_Slider(
   50.00,
   "Max Alpha",
   0,100);

mLifetime = GUI_Slider(
   6.00,
   "Particle life time",
   0,15);

mRotation = GUI_Slider(
   -133.00,
   "Rotation",
   -270,-90);

mEmitSpeed = GUI_Slider(
   0.80,
      "Emitter Speed",
      0,10);

mRadiusX = GUI_Slider(
   99.90,
      "Radius X",
      0,300);
mRadiusY = GUI_Slider(
   73.20,
      "Radius Y",
      0,200);

mTextureName = GUI_PickTexture("fx/laboratory/light_ray","Particle Texture");

mBlendMode = GUI_Select(
   kBlendAdditiveAlpha,
      "Blend Mode",
      {
         { description="Normal", value=kBlendNormal},
         { description="Additive", value=kBlendAdditiveAlpha}
      }
);

-- ------------------------------------------------------------
-- Globals

gActive = true;

-- ------------------------------------------------------------
-- Define our particle characteristics
pVelocity = Allocate(2);
pFadeStart = Allocate(1);
pFadeEnd = Allocate(1);
pFadeTime = Allocate(1);
pAge = Allocate(1);
pSpin = Allocate(1);

SetTexture(mTextureName);
SetBlendMode(mBlendMode);

SetNumParticles(mLifetime*mEmitSpeed+1);

-- ------------------------------------------------------------
-- Initialization rules.
-- 
-- The following rules define how particles are created.

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

pPosition:Init(Vec2(fRange(-mRadiusX, mRadiusX), fRange(-mRadiusY, mRadiusY)) + dLocus);
pAge:Init(0);
pUp:Init(f2dRotation(mRotation / 180 * 3.1415927));
pFadeStart:Init(fRange(mLifetime*1000/3, mLifetime*2000/3));
pFadeEnd:Init(mLifetime*1000);
pFadeTime:Init(pFadeEnd-pFadeStart);
pScale:Init(1);

-- ------------------------------------------------------------
-- Particle Parameter Animation Functions
--
-- The following rules define how particles animate.
-- Each rule is applied on each frame of animation.
pAge:Anim( pAge+fAge() );
pColor:Anim( 
   fFade( pAge,
      Color(1,1,1,0), pFadeStart,
      Color(1,1,1,mMaxAlpha/100), pFadeTime,
      Color(1,1,1,0) )
   );


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

-- ------------------------------------------------------------

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

function Update(seconds)
   if gActive then
     CreateParticles(seconds * mEmitSpeed);
   end -- gActive
end

