-- Define our particle characteristics
pAge = Allocate(1) ; -- Allocate a TReal age member
pSpin = Allocate(1); -- Allocate a TReal spin member
pOriginalRadius = Allocate(1); -- Allocate a TReal radius member
pRadius = Allocate(1); -- Allocate a TReal radius member
pSpinSpeed = Allocate(1); -- Allocate a TReal spin member
pAngleX = Allocate(1);
pAngleY = Allocate(1);
pX = Allocate(1);
pY = Allocate(1);
pOriginalX = Allocate(1);
pOriginalY = Allocate(1);

-- Set the particle texture
SetTexture("lecarre");
SetBlendMode(kBlendSubtractive);

SetNumParticles(5000);    -- Create some particles
pOriginalRadius:Init( 3 ); -- rayon en pixel
pRadius:Init( 3 ); -- rayon en pixel
pColor:Init( Color(1,1,1,1) );
pScale:Init( 1 );
pAge:Init(0);
pAngleX:Init(f2dRotation(fAngleCircle(0,64))[1]);
pAngleY:Init(f2dRotation(fAngleCircle(0,64))[2]);

pOriginalX:Init(pAngleX*pRadius + dLocus[1]);
pOriginalY:Init(pAngleY*pRadius + dLocus[2]);

pX:Init(0);
pY:Init(0);
pPosition:Init(Vec2(pOriginalX,pOriginalY));  -- position around dlocus

pSpin:Init( fRange( 0, 2*3.1415927 ));
pSpinSpeed:Init(35);

--pPosition:Anim(pPosition); -- f2dRotation(NextAngle(nb part));
 
pRadius:Anim(pRadius + 0.50); -- en px

pX:Anim( pOriginalX + (pRadius * fCos(pAngleX)));
pY:Anim( pOriginalY + (pRadius * fSin(pAngleY)));

pPosition:Anim(Vec2(pX,pY));


-- pScale:Anim( fClosedCycle(5,0,900) );
pColor:Anim( pColor );
 -- pSpin:Anim( pSpin + fTimeScale(pSpinSpeed)  );

--Pup rotation
-- pUp:Anim(  f2dRotation( pSpin )  ); --fClosedCycle(5,0,900) + 
-- Add time to the age
pAge:Anim( pAge+fAge() );

-- Expire particles over 1500 ms old
Anim( fExpire( fGreater(pAge,1000) ) );

-- Create an initial particle
CreateParticles( 0 );

-- A function to run as we're executing
-- seconds - how many seconds have elapsed
function Update(seconds)
   -- Create 10 particles per second
   CreateParticles( seconds * 128 );
end

