BrumeParticleSystem processor

You can help us to improve Brume ! Post your contribs here and we will try to integrate them in next release for other users !

Moderator: Brume Dev Team

BrumeParticleSystem processor

Postby Gero on Thu Jan 03, 2008 12:17 pm

Hi,

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);
User avatar
Gero
Brume user
 
Posts: 27
Joined: Thu Dec 06, 2007 10:11 pm

Re: BrumeParticleSystem processor

Postby Silmaryls on Tue Jan 08, 2008 8:19 pm

Hi Gero !

Thx for the contrib. Do you have something visual to illustrate the code ?
Should be nice...

Silmaryls
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Re: BrumeParticleSystem processor

Postby Gero on Thu Jan 10, 2008 9:13 pm

Hi,

just think of a Object with attached particle stream which is colored like a rainbow.
I'll make some screenshots in some days.
User avatar
Gero
Brume user
 
Posts: 27
Joined: Thu Dec 06, 2007 10:11 pm


Return to Contribs

Who is online

Users browsing this forum: No registered users and 1 guest

cron