this class is a processor for a particle system NOT a particle processor.
The class calculates a new emitter color based on the speed.
When a particle system is set the color seems like a rainbow over time.
- Code: Select all
public class RainbowFX : BrumeObject
{
#region Fields
private float colorSpeed = 1.0f;
private float colorTime;
private BrumeParticleSystem fxSystem;
#endregion
#region Properties
public float ColorSpeed
{
get { return colorSpeed; }
set { colorSpeed = value; }
}
public BrumeParticleSystem FxSystem
{
get { return fxSystem; }
set { fxSystem = value; }
}
#endregion
public RainbowFX(BrumeParticleSystem FxSystem)
: base(FxSystem.brume, FxSystem.Name + " RainboxFX")
{
this.FxSystem = FxSystem;
}
public override void Move(float fElapsedTime)
{
base.Move(fElapsedTime);
colorTime += fElapsedTime / 1000.0f * colorSpeed;
colorTime %= 360.0f;
if (colorTime < 0f || colorTime > 360.0f)
throw new Exception("wrong colortime value");
if (FxSystem != null)
FxSystem.Color = CalcColor(colorTime);
}
private System.Drawing.Color CalcColor(float H)
{
float R;
float G;
float B;
const float S = 1.0f;
const float V = 1.0f;
if (V == 0)
{
R = 0; G = 0; B = 0;
}
else if (S == 0)
{
R = V; G = V; B = V;
}
else
{
float hf = H / 60.0f;
int i = (int)(hf);
float f = hf - i;
float pv = V * (1.0f - S);
float qv = V * (1.0f - S * f);
float tv = V * (1.0f - S * (1.0f - f));
switch (i)
{
case 0:
R = V; G = tv; B = pv;
break;
case 1:
R = qv; G = V; B = pv;
break;
case 2:
R = pv; G = V; B = tv;
break;
case 3:
R = pv; G = qv; B = V;
break;
case 4:
R = tv; G = pv; B = V;
break;
case 5:
R = V; G = pv; B = qv;
break;
case 6:
R = V; G = tv; B = pv;
break;
case -1:
R = V; G = pv; B = qv;
break;
default:
throw new Exception("i Value error in Pixel conversion, Value is wrong");
}
}
R *= 255.0F; G *= 255.0F; B *= 255.0F;
if (R > 255.0f || G > 255.0f || B > 255.0f)
throw new Exception("Wrong color value");
if (R < 0f || G < 0f || B < 0f)
throw new Exception("Wrong color value");
return System.Drawing.Color.FromArgb((int)R, (int)G, (int)B);
}
}
Use it with this code:
- Code: Select all
BrumeParticleSystem FxSystem;
//Your system inits here
RainbowFX Rainbow = new RainbowFX(FxSystem);
Rainbow.ColorSpeed = 100.0f;
FxSystem.AddChild(Rainbow);