kRed = GUI_Slider(
   255.00, "Red", 0, 255 );
kGreen = GUI_Slider(
	0.00, "Green", 0, 255 );
kBlue = GUI_Slider(
	0.00, "Blue", 0, 255 );
kMaxAlpha = GUI_Slider(
   1.00, "Max Alpha", 0, 1 );
kScaleStart = GUI_Slider(
   0.10, "Start Scale", 0, 5 );
kScaleInc = GUI_Slider(
   0.00, "Inc Scale", 0, 5 );
kLifeMin = GUI_Slider(
   4000.00, "Life Min", 0, 20000 );
kLifeMax = GUI_Slider(
   7000.00, "Life Max", 0, 20000 );
kEmitSpeed = GUI_Slider(
   1.00, "Emit Speed", 0, 1000 );
kBlending = GUI_Select(
    kBlendAdditiveAlpha ,
   "Blend Mode",
   {
    { description = "Normal", value = kBlendNormal },
    { description = "Additive", value = kBlendAdditiveAlpha }
   } );

kRed = kRed / 255;
kGreen = kGreen / 255;
kBlue = kBlue / 255;

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

pVelocity = Allocate( 2 );
pAge = Allocate( 1 );
pRed = Allocate( 1 );
pGreen = Allocate( 1 );
pBlue = Allocate( 1 );
pColorAdjust = Allocate( 1 );
pLifeSpan = Allocate( 1 );
pSin = Allocate( 1 );
pSinWidth = Allocate( 1 );
pSinSpeed = Allocate( 1 );

SetTexture( "particles/smoke" );
SetBlendMode( kBlending );
SetNumParticles( kEmitSpeed * ( kLifeMax / 1000 ) );

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

if not dLocus then
   dLocus = Vec2( 153, 333 );
end

if not dSize then
	dSize = Vec2( 15, 0 );
end

pSin:Init( fRange( 0, 1 ) );
pSinSpeed:Init( fRange( 0, 1 ) );
pSinWidth:Init( fRange( 0, 10 ) );
pColorAdjust:Init( fRange( 0.0, 1.0 ) );
pRed:Init( ( pColorAdjust * ( 1.0 - kRed ) ) + kRed );
pGreen:Init( ( pColorAdjust * ( 1.0 - kGreen ) ) + kGreen );
pBlue:Init( ( pColorAdjust * ( 1.0 - kBlue ) ) + kBlue );
pPosition:Init( dLocus + Vec2( fRange( 0, dSize[1] * 2 ) - dSize[1], 
							   fRange( 0, dSize[2] * 2 ) - dSize[2] ) );
pVelocity:Init( fRange( Vec2( -0.75, -6 ), Vec2( 0.75, -6 ) ) );
pScale:Init( kScaleStart );
pAge:Init( 0 );
pLifeSpan:Init( fRange( kLifeMin, kLifeMax ) );

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

pSin:Anim( pSin + fTimeScale( pSinSpeed ) );
pPosition:Anim( Vec2( pPosition[1] + fTimeScale( pVelocity[1] ) + fTimeScale( fSin( pSin * 3.14159 ) * pSinWidth ),
					  pPosition[2] + fTimeScale( pVelocity[2] ) ) );
pScale:Anim( pScale + fTimeScale( kScaleInc ) );

pColor:Anim( 
   fFade( pAge,
         Color( pRed, pGreen, pBlue, 0 ), 500,
         Color( pRed, pGreen, pBlue, kMaxAlpha ), pLifeSpan,
         Color( pRed, pGreen, pBlue, 0 ) ) );

pAge:Anim( pAge + fAge() );

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

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

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