kRed = GUI_Slider(
   240.00, "Red", 0, 255 );
kGreen = GUI_Slider(
   210.00, "Green", 0, 255 );
kBlue = GUI_Slider(
   0.00, "Blue", 0, 255 );
kScaleMin = GUI_Slider(
   0.25, "Min Scale", 0, 5 );
kScaleMax = GUI_Slider(
   1.00, "Max Scale", 0, 5 );
kLifeMin = GUI_Slider(
	500.00, "Life Min", 0, 20000 );
kLifeMax = GUI_Slider(
	500.00, "Life Max", 0, 20000 );
kEmitSpeed = GUI_Slider(
   60.00, "Emit Speed", 0, 1000 );
kParticleMax = GUI_Slider(
   400.00, "Particle Max", 0, 10000 );
kMaxAlpha = GUI_Slider(
   1, "Max Alpha", 0, 1 );
kBlending = GUI_Select(
    kBlendNormal,
   "Blend Mode",
   {
    { description = "Normal", value = kBlendNormal },
    { description = "Additive", value = kBlendAdditiveAlpha }
   } );

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

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

pAge = Allocate( 1 );
pSpin = Allocate( 1 );
pSpinSpeed = Allocate( 1 );
pVelocity = Allocate( 2 );
pRed = Allocate( 1 );
pGreen = Allocate( 1 );
pBlue = Allocate( 1 );
pColorAdjust = Allocate( 1 );
pLifeSpan = Allocate( 1 );

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

SetTexture( "particles/particlespark" );
SetBlendMode( kBlending );
SetNumParticles( kParticleMax );

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

dVelocity = 100;

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

if not dSize then
   dSize = 15;
end

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

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 );
pColor:Init( Color( pRed, pGreen, pBlue, 0 ) );
pLifeSpan:Init( fRange( kLifeMin, kLifeMax ) );
pAge:Init( 0 );
pSpin:Init( fRange( 0, 2 * 3.1415927 ) );
pSpinSpeed:Init( fRange( -1, 1 ) );
pPosition:Init( fRange( dLocus - dSize, dLocus + dSize ) );
pScale:Init( fRange( kScaleMin, kScaleMax ) );
pVelocity:Init( Vec2( fRange( -dVelocity, dVelocity ), fRange( -dVelocity, dVelocity ) ) );

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

pSpin:Anim( pSpin + pSpinSpeed );
pUp:Anim( f2dRotation( pSpin ) );
pScale:Anim( pScale + fRange( -0.05, 0.05 ) );
pColor:Anim( fFade( pAge, 
               Color( pRed, pGreen, pBlue, 0 ), 100,
               Color( pRed, pGreen, pBlue, kMaxAlpha ), pLifeSpan, 
               Color( pRed, pGreen, pBlue, 0 ) ) );
pPosition:Anim( pPosition + fTimeScale( pVelocity ) );
pAge:Anim( pAge + fAge() );

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

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

gActive = 0;

function Update( seconds )
    if gActive > 0 then
        CreateParticles( seconds * kEmitSpeed );
    end
end