コード例 #1
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            int    colorcnt          = Colors.Count;
            var    intervalPosFactor = GetEffectTimeIntervalPosition(frame) * 100;
            double level             = LevelCurve.GetValue(intervalPosFactor) / 100;
            var    length            = CalculateLength(intervalPosFactor);
            int    tailLength        = BufferHt < 10 ? length / 10 : BufferHt * length / 100;
            int    minDirection      = 1;
            int    maxDirection      = 360;
            int    pixelCount        = CalculatePixelCount(intervalPosFactor);
            double centerSpeed       = CalculateCenterSpeed(intervalPosFactor);
            double spreadSpeed       = CalculateSpeedVariation(intervalPosFactor);
            double minSpeed          = centerSpeed - (spreadSpeed / 2);
            double maxSpeed          = centerSpeed + (spreadSpeed / 2);

            if (minSpeed < 1)
            {
                minSpeed = 1;
            }
            if (maxSpeed > 200)
            {
                maxSpeed = 200;
            }
            if (tailLength < 1)
            {
                tailLength = 1;
            }

            // create new meteors and maintain maximum number as per users selection.
            HSV hsv;
            int adjustedPixelCount;

            if (frame < pixelCount)
            {
                if (MeteorStartPosition == MeteorStartPosition.InitiallyRandom && frame > pixelCount)
                {
                    adjustedPixelCount = 1;
                }
                else if (MeteorStartPosition == MeteorStartPosition.ZeroPosition)
                {
                    adjustedPixelCount = pixelCount;
                }
                else
                {
                    adjustedPixelCount = pixelCount < 10 ? pixelCount : pixelCount / 10;
                }
            }
            else
            {
                adjustedPixelCount = pixelCount;
            }

            int stringCount = 1;

            if (CountPerString && MeteorPerString)
            {
                stringCount = BufferWi;
            }

            for (int i = 0; i < adjustedPixelCount; i++)
            {
                for (int j = 0; j < stringCount; j++)
                {
                    if (_meteors.Count >= pixelCount * stringCount)
                    {
                        break;
                    }
                    double      position = (RandDouble() * ((maxSpeed) - minSpeed) + minSpeed) / 20;
                    MeteorClass m        = new MeteorClass();
                    if (MeteorEffect == MeteorsEffect.RandomDirection)
                    {
                        minDirection = MinDirection;
                        maxDirection = MaxDirection;
                    }

                    int direction;
                    if (MeteorEffect == MeteorsEffect.None)
                    {
                        direction =
                            Direction;                             //Set Range for standard Meteor as we don't want to just have them going straight down or two dirctions like the original Meteor effect.
                    }
                    else
                    {
                        //This is to generate random directions between the Min and Max values
                        //However if Someone makes the MaxDirection lower then the Min Direction then
                        //the new direction will be the inverserve of the Min and Max effectively changing
                        //the range from a downward motion to an upward motion, increasing the feature capability.
                        if (maxDirection <= minDirection)
                        {
                            //used for the Upward movement of the Meteor (added feature)
                            direction = Rand(1, 3) == 1 ? Rand(1, maxDirection) : Rand(minDirection, 360);
                        }
                        else
                        {
                            //used for the downward movemnet of the Meteor (standard way)
                            direction = Rand(minDirection, maxDirection);
                        }
                    }

                    //Moving
                    if (!CountPerString)
                    {
                        m.X = Rand() % BufferWi;
                    }
                    m.Y = Rand() % BufferHt;
                    if (MeteorPerString)
                    {
                        m.TailY = FlipDirection ? 1 : -1;

                        if (CountPerString)
                        {
                            var meteorExists = false;
                            foreach (var meteor in _meteors)
                            {
                                if (meteor.X == j)
                                {
                                    meteorExists = true;
                                    break;
                                }
                            }

                            if (meteorExists)
                            {
                                continue;
                            }
                            m.X = j;
                        }

                        m.DeltaY = m.TailY * position;
                        m.Y      = Rand() % BufferHt;
                    }
                    else if (direction >= 0 && direction <= 90)
                    {
                        m.TailX  = ((double)direction / 90);
                        m.DeltaX = m.TailX * position;
                        m.TailY  = ((double)Math.Abs(direction - 90) / 90);
                        m.DeltaY = m.TailY * position;
                        if (RandDouble() >= (double)(90 - direction) / 100)
                        {
                            m.X = 0;
                            m.Y = Rand() % BufferHt;
                        }
                        else
                        {
                            m.X = Rand() % BufferWi;
                            m.Y = 0;
                        }
                    }
                    else if (direction > 90 && direction <= 180)
                    {
                        m.TailX  = ((double)Math.Abs(direction - 180) / 90);
                        m.DeltaX = m.TailX * position;
                        m.TailY  = -1 * ((double)Math.Abs(direction - 90) / 90);
                        m.DeltaY = m.TailY * position;
                        if (RandDouble() >= (double)(180 - direction) / 100)
                        {
                            m.X = Rand() % BufferWi;
                            m.Y = BufferHt;
                        }
                        else
                        {
                            m.X = 0;
                            m.Y = Rand() % BufferHt;
                        }
                    }
                    else if (direction > 180 && direction <= 270)
                    {
                        m.TailX  = -1 * ((double)Math.Abs(direction - 180) / 90);
                        m.DeltaX = m.TailX * position;
                        m.TailY  = -1 * ((double)Math.Abs(direction - 270) / 90);
                        m.DeltaY = m.TailY * position;
                        if (RandDouble() >= (double)(270 - direction) / 100)
                        {
                            m.X = BufferWi;
                            m.Y = Rand() % BufferHt;
                        }
                        else
                        {
                            m.X = Rand() % BufferWi;
                            m.Y = BufferHt;
                        }
                    }
                    else if (direction > 270 && direction <= 360)
                    {
                        m.TailX  = -1 * ((double)Math.Abs(direction - 360) / 90);
                        m.DeltaX = m.TailX * position;
                        m.TailY  = ((double)Math.Abs(270 - direction) / 90);
                        m.DeltaY = m.TailY * position;
                        if (RandDouble() >= (double)(360 - direction) / 100)
                        {
                            m.X = Rand() % BufferWi;
                            m.Y = 0;
                        }
                        else
                        {
                            m.X = BufferWi;
                            m.Y = Rand() % BufferHt;
                        }
                    }

                    if (MeteorEffect == MeteorsEffect.Explode)
                    {
                        m.X = (BufferWi - 1) / 2;
                        m.Y = (BufferHt - 1) / 2;
                    }
                    else
                    {
                        if (MeteorStartPosition == MeteorStartPosition.ZeroPosition)
                        {
                            if (MeteorPerString)
                            {
                                m.Y = FlipDirection ? 0 : BufferHt;
                            }
                        }
                        else if (MeteorStartPosition == MeteorStartPosition.Random || frame < pixelCount)
                        {
                            if (!MeteorPerString)
                            {
                                m.X = Rand() % BufferWi - 1;
                            }
                            m.Y = BufferHt - 1 <= _maxGroundHeight ? 0 : Rand(_maxGroundHeight, BufferHt - 1);
                        }
                    }

                    m.DeltaXOrig = m.DeltaX;
                    m.DeltaYOrig = m.DeltaY;

                    switch (ColorType)
                    {
                    case MeteorsColorType.Range:                             //Random two colors are selected from the list for each meteor.
                        m.Hsv =
                            SetRangeColor(
                                HSV.FromRGB(Colors[Rand() % colorcnt].GetColorAt((intervalPosFactor) / 100)),
                                HSV.FromRGB(Colors[Rand() % colorcnt].GetColorAt((intervalPosFactor) / 100)));
                        break;

                    case MeteorsColorType.Palette:                             //All colors are used
                        m.Hsv = HSV.FromRGB(Colors[Rand() % colorcnt].GetColorAt((intervalPosFactor) / 100));
                        break;

                    case MeteorsColorType.Gradient:
                        m.Color           = Rand() % colorcnt;
                        _gradientPosition = 100 / (double)tailLength / 100;
                        m.Hsv             = HSV.FromRGB(Colors[m.Color].GetColorAt(0));
                        break;
                    }

                    m.HsvBrightness = RandomBrightness ? RandDouble() * (1.0 - .20) + .20 : 1;
                    _meteors.Add(m);
                }
            }

            if (EnableGroundLevel)
            {
                hsv    = HSV.FromRGB(GroundColor.GetColorAt((intervalPosFactor) / 100));
                hsv.V *= LevelCurve.GetValue(intervalPosFactor) / 100;
                for (int x = 0; x < BufferWi; x++)
                {
                    for (int y = 0; y < CalculateGroundLevel(((double)100 / BufferWi) * x); y++)
                    {
                        if (_tempBuffer.GetColorAt(x, y) != Color.Empty)
                        {
                            frameBuffer.SetPixel(x, y, hsv);
                        }
                    }
                }
            }

            // render meteors
            foreach (MeteorClass meteor in _meteors)
            {
                meteor.DeltaX += meteor.DeltaXOrig;
                meteor.DeltaY += meteor.DeltaYOrig;
                int colorX = meteor.X + (int)meteor.DeltaX - BufferWi / 100;
                int colorY = meteor.Y + (int)meteor.DeltaY + BufferHt / 100;

                for (int ph = 0; ph < tailLength; ph++)
                {
                    switch (ColorType)
                    {
                    case MeteorsColorType.RainBow:                             //No user colors are used for Rainbow effect.
                        meteor.Hsv.H = (float)(Rand() % 1000) / 1000.0f;
                        meteor.Hsv.S = 1.0f;
                        meteor.Hsv.V = 1.0f;
                        break;

                    case MeteorsColorType.Gradient:
                        meteor.Hsv = HSV.FromRGB(Colors[meteor.Color].GetColorAt(_gradientPosition * ph));
                        break;
                    }
                    hsv    = meteor.Hsv;
                    hsv.V *= meteor.HsvBrightness * (float)(1.0 - (double)ph / tailLength) * level;
                    //var decPlaces = (int) (((decimal) (meteor.TailX*ph)%1)*100);
                    var decPlaces = (int)(meteor.TailX * ph % 1d * 100);
                    if (decPlaces <= 40 || decPlaces >= 60)
                    {
                        if (MeteorEffect == MeteorsEffect.Explode && ph > 0 && (colorX == (BufferWi / 2) + (int)(Math.Round(meteor.TailX * ph)) || colorX == (BufferWi / 2) - (int)(Math.Round(meteor.TailX * ph)) || colorY == (BufferHt / 2) + (int)(Math.Round(meteor.TailY * ph)) || colorY == (BufferHt / 2) - (int)(Math.Round(meteor.TailY * ph))))
                        {
                            break;
                        }
                        frameBuffer.SetPixel(colorX - (int)(Math.Round(meteor.TailX * ph)), colorY - (int)(Math.Round(meteor.TailY * ph)),
                                             hsv);
                    }
                }

                if (colorX > 0 && colorX < BufferWi - 1 && colorY > 0 && colorY < BufferHt && EnableGroundLevel)
                {
                    if (!_tempBuffer.GetColorAt(colorX, colorY).IsEmpty)
                    {
                        if (frame > 1)
                        {
                            _tempBuffer.SetPixel(colorX, colorY, Color.Empty);
                            _tempBuffer.SetPixel(colorX, colorY - 1, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 1, colorY, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 1, colorY, Color.Empty);
                            _tempBuffer.SetPixel(colorX, colorY + 1, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 1, colorY + 1, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 1, colorY + 1, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 1, colorY + 2, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 1, colorY + 2, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 1, colorY + 3, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 1, colorY + 3, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 2, colorY + 3, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 2, colorY + 3, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 2, colorY + 2, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 2, colorY + 2, Color.Empty);
                            _tempBuffer.SetPixel(colorX, colorY + 2, Color.Empty);
                            _tempBuffer.SetPixel(colorX, colorY + 3, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 2, colorY + 4, Color.Empty);
                            _tempBuffer.SetPixel(colorX - 1, colorY + 4, Color.Empty);
                            _tempBuffer.SetPixel(colorX, colorY + 4, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 1, colorY + 4, Color.Empty);
                            _tempBuffer.SetPixel(colorX + 2, colorY + 4, Color.Empty);
                        }
                        meteor.Expired = true;
                    }
                }

                if (colorX >= BufferWi + tailLength || colorY >= BufferHt + tailLength || colorX < 0 - tailLength ||
                    colorY < 0 - tailLength)
                {
                    meteor.Expired = true;                     //flags Meteors that have reached the end of the grid as expiried.
                    //	break;
                }
            }

            // delete old meteors
            int meteorNum = 0;

            while (meteorNum < _meteors.Count)
            {
                if (_meteors[meteorNum].Expired)
                {
                    _meteors.RemoveAt(meteorNum);
                }
                else
                {
                    meteorNum++;
                }
            }
        }
コード例 #2
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            if (frame == 0)
            {
                _meteors.Clear();
            }
            int colorcnt     = Colors.Count();
            int tailLength   = (BufferHt < 10) ? Length / 10 : BufferHt * Length / 100;
            int minDirection = 1;
            int maxDirection = 360;

            if (tailLength < 1)
            {
                tailLength = 1;
            }
            int tailStart = BufferHt;

            if (tailStart < 1)
            {
                tailStart = 1;
            }

            // create new meteors and maintain maximum number as per users selection.
            HSV hsv        = new HSV();
            int pixelCount = frame < PixelCount
                                ? (!RandomMeteorPosition && frame > PixelCount ? 1 : (PixelCount < 10 ? PixelCount : PixelCount / 10))
                                : PixelCount;

            for (int i = 0; i < pixelCount; i++)
            {
                double position = RandomSpeed ? (double)_random.Next(MinSpeed, MaxSpeed + 1) / 20 : (double)Speed / 20;
                if (_meteors.Count >= PixelCount)
                {
                    continue;
                }
                MeteorClass m = new MeteorClass();
                if (MeteorEffect == MeteorsEffect.RandomDirection)
                {
                    minDirection = MinDirection;
                    maxDirection = MaxDirection;
                }

                int direction;
                if (MeteorEffect == MeteorsEffect.None)
                {
                    direction = Direction;                     //Set Range for standard Meteor as we don't want to just have them going straight down or two dirctions like the original Meteor effect.
                }
                else
                {
                    //This is to generate random directions between the Min and Max values
                    //However if Someone makes the MaxDirection lower then the Min Direction then
                    //the new direction will be the inverserve of the Min and Max effectively changing
                    //the range from a downward motion to an upward motion, increasing the feature capability.
                    if (maxDirection <= minDirection)
                    {
                        //used for the Upward movement of the Meteor (added feature)
                        direction = _random.Next(1, 3) == 1 ? _random.Next(1, maxDirection) : _random.Next(minDirection, 360);
                    }
                    else
                    {
                        //used for the downward movemnet of the Meteor (standard way)
                        direction = _random.Next(minDirection, maxDirection);
                    }
                }
                //Moving
                m.X = rand() % BufferWi;
                m.Y = rand() % BufferHt;
                if (direction >= 0 && direction <= 90)
                {
                    m.TailX  = ((double)direction / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY  = ((double)Math.Abs(direction - 90) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(90 - direction) / 100)
                    {
                        m.X = 0;
                        m.Y = rand() % BufferHt;
                    }
                    else
                    {
                        m.X = rand() % BufferWi;
                        m.Y = 0;
                    }
                }
                else if (direction > 90 && direction <= 180)
                {
                    m.TailX  = ((double)Math.Abs(direction - 180) / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY  = -1 * ((double)Math.Abs(direction - 90) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(180 - direction) / 100)
                    {
                        m.X = rand() % BufferWi;
                        m.Y = BufferHt;
                    }
                    else
                    {
                        m.X = 0;
                        m.Y = rand() % BufferHt;
                    }
                }
                else if (direction > 180 && direction <= 270)
                {
                    m.TailX  = -1 * ((double)Math.Abs(direction - 180) / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY  = -1 * ((double)Math.Abs(direction - 270) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(270 - direction) / 100)
                    {
                        m.X = BufferWi;
                        m.Y = rand() % BufferHt;
                    }
                    else
                    {
                        m.X = rand() % BufferWi;
                        m.Y = BufferHt;
                    }
                }
                else if (direction > 270 && direction <= 360)
                {
                    m.TailX  = -1 * ((double)Math.Abs(direction - 360) / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY  = ((double)Math.Abs(270 - direction) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(360 - direction) / 100)
                    {
                        m.X = rand() % BufferWi;
                        m.Y = 0;
                    }
                    else
                    {
                        m.X = BufferWi;
                        m.Y = rand() % BufferHt;
                    }
                }

                if (MeteorEffect == MeteorsEffect.Explode)
                {
                    m.X = BufferWi / 2;
                    m.Y = BufferHt / 2;
                }
                else
                {
                    if (RandomMeteorPosition || frame < PixelCount)
                    {
                        m.X = rand() % BufferWi;
                        m.Y = (BufferHt - 1 - (rand() % tailStart));
                    }
                }
                m.DeltaXOrig = m.DeltaX;
                m.DeltaYOrig = m.DeltaY;

                switch (ColorType)
                {
                case MeteorsColorType.Range:                         //Random two colors are selected from the list for each meteor.
                    m.Hsv =
                        SetRangeColor(HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)),
                                      HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100)));
                    break;

                case MeteorsColorType.Palette:                         //All colors are used
                    m.Hsv = HSV.FromRGB(Colors[rand() % colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                    break;

                case MeteorsColorType.Gradient:
                    m.Color           = rand() % colorcnt;
                    _gradientPosition = 100 / (double)tailLength / 100;
                    m.Hsv             = HSV.FromRGB(Colors[m.Color].GetColorAt(0));
                    break;
                }
                m.HsvBrightness = RandomBrightness ? _random.NextDouble() * (1.0 - .25) + .25 : 1;
                _meteors.Add(m);
            }

            // render meteors
            foreach (MeteorClass meteor in _meteors)
            {
                meteor.DeltaX += meteor.DeltaXOrig;
                meteor.DeltaY += meteor.DeltaYOrig;
                int colorX = (meteor.X + Convert.ToInt32(meteor.DeltaX) - (BufferWi / 100));
                int colorY = (meteor.Y + Convert.ToInt32(meteor.DeltaY) + (BufferHt / 100));

                for (int ph = 0; ph < tailLength; ph++)
                {
                    switch (ColorType)
                    {
                    case MeteorsColorType.RainBow:                             //No user colors are used for Rainbow effect.
                        meteor.Hsv.H = (float)(rand() % 1000) / 1000.0f;
                        meteor.Hsv.S = 1.0f;
                        meteor.Hsv.V = 1.0f;
                        break;

                    case MeteorsColorType.Gradient:
                        meteor.Hsv = HSV.FromRGB(Colors[meteor.Color].GetColorAt(_gradientPosition * ph));
                        break;
                    }
                    hsv    = meteor.Hsv;
                    hsv.V *= meteor.HsvBrightness;
                    hsv.V *= (float)(1.0 - ((double)ph / tailLength) * 0.75);
                    //Adjusts the brightness based on the level curve
                    hsv.V = hsv.V * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
                    var decPlaces = (int)(((decimal)(meteor.TailX * ph) % 1) * 100);
                    if (decPlaces <= 40 || decPlaces >= 60)
                    {
                        frameBuffer.SetPixel(colorX - (int)(Math.Round(meteor.TailX * ph)), colorY - (int)(Math.Round(meteor.TailY * ph)),
                                             hsv);
                    }
                }
                if (colorX >= BufferWi + tailLength || colorY >= BufferHt + tailLength || colorX < 0 - tailLength ||
                    colorY < 0 - tailLength)
                {
                    meteor.Expired = true;                     //flags Meteors that have reached the end of the grid as expiried.
                    //	break;
                }
            }

            // delete old meteors
            int meteorNum = 0;

            while (meteorNum < _meteors.Count)
            {
                if (_meteors[meteorNum].Expired)
                {
                    _meteors.RemoveAt(meteorNum);
                }
                else
                {
                    meteorNum++;
                }
            }
        }
コード例 #3
0
ファイル: NutcrackerEffects.cs プロジェクト: komby/vixen
        private void RenderMeteors(int MeteorType, int Count, int Length)
        {
            if (State == 0)
                meteors.Clear();
            int mspeed = (int) State/4;
            State -= mspeed*4 - 1;

            // create new meteors
            HSV hsv = new HSV();
            HSV hsv0 = new HSV();
            HSV hsv1 = new HSV();
            hsv0 = Palette.GetHSV(0);
            hsv1 = Palette.GetHSV(1);
            int colorcnt = GetColorCount();
            Count = BufferWi*Count/100;
            int TailLength = (BufferHt < 10) ? Length/10 : BufferHt*Length/100;
            if (TailLength < 1) TailLength = 1;
            int TailStart = BufferHt - TailLength;
            if (TailStart < 1) TailStart = 1;
            for (int i = 0; i < Count; i++) {
                MeteorClass m = new MeteorClass();
                m.x = rand()%BufferWi;
                m.y = BufferHt - 1 - (rand()%TailStart);
                switch (MeteorType) {
                    case 1:
                        m.hsv = HSV.SetRangeColor(hsv0, hsv1);
                        break;
                    case 2:
                        m.hsv = Palette.GetHSV(rand()%colorcnt);
                        break;
                }
                meteors.Add(m);
            }

            // render meteors
            foreach (MeteorClass meteor in meteors) {
                {
                    for (int ph = 0; ph < TailLength; ph++) {
                        switch (MeteorType) {
                            case 0:
                                hsv.Hue = (float) (rand()%1000)/1000.0f;
                                hsv.Saturation = 1.0f;
                                hsv.Value = 1.0f;
                                break;
                            default:
                                hsv.SetToHSV(meteor.hsv);
                                break;
                        }
                        hsv.Value *= (float) (1.0 - (double) ph/TailLength);
                        SetPixel(meteor.x, meteor.y + ph, hsv);
                    }
                    meteor.y -= mspeed;
                }
            }
            // delete old meteors
            int meteorNum = 0;
            while (meteorNum < meteors.Count) {
                if (meteors[meteorNum].HasExpired(TailLength)) {
                    meteors.RemoveAt(meteorNum);
                }
                else {
                    meteorNum++;
                }
            }
        }
コード例 #4
0
ファイル: Meteors.cs プロジェクト: jaredb7/vixen
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            if (frame == 0)
                _meteors.Clear();
            int colorcnt = Colors.Count();
            int tailLength = (BufferHt < 10) ? Length/10 : BufferHt*Length/100;
            int minDirection = 1;
            int maxDirection = 360;
            if (tailLength < 1) tailLength = 1;
            int tailStart = BufferHt;
            if (tailStart < 1) tailStart = 1;

            // create new meteors and maintain maximum number as per users selection.
            HSV hsv = new HSV();
            int pixelCount = frame < PixelCount
                ? (!RandomMeteorPosition && frame > PixelCount ? 1 : (PixelCount < 10 ? PixelCount : PixelCount / 10))
                : PixelCount;

            for (int i = 0; i < pixelCount; i++)
            {
                double position = RandomSpeed ? (double)_random.Next(MinSpeed, MaxSpeed + 1) / 20 : (double)Speed / 20;
                if (_meteors.Count >= PixelCount) continue;
                MeteorClass m = new MeteorClass();
                if (MeteorEffect == MeteorsEffect.RandomDirection)
                {
                    minDirection = MinDirection;
                    maxDirection = MaxDirection;
                }

                int direction;
                if (MeteorEffect == MeteorsEffect.None)
                    direction = Direction; //Set Range for standard Meteor as we don't want to just have them going straight down or two dirctions like the original Meteor effect.
                else
                {
                    //This is to generate random directions between the Min and Max values
                    //However if Someone makes the MaxDirection lower then the Min Direction then
                    //the new direction will be the inverserve of the Min and Max effectively changing
                    //the range from a downward motion to an upward motion, increasing the feature capability.
                    if (maxDirection <= minDirection)
                    {
                        //used for the Upward movement of the Meteor (added feature)
                        direction = _random.Next(1, 3) == 1 ? _random.Next(1, maxDirection) : _random.Next(minDirection, 360);
                    }
                    else
                    {
                        //used for the downward movemnet of the Meteor (standard way)
                        direction = _random.Next(minDirection, maxDirection);
                    }
                }
                //Moving
                m.X = rand() % BufferWi;
                m.Y = rand() % BufferHt;
                if (direction >= 0 && direction <= 90)
                {
                    m.TailX = ((double)direction / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY = ((double)Math.Abs(direction - 90) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(90 - direction) / 100)
                    {
                        m.X = 0;
                        m.Y = rand() % BufferHt;
                    }
                    else
                    {
                        m.X = rand()%BufferWi;
                        m.Y = 0;
                    }
                }
                else if (direction > 90 && direction <= 180)
                {
                    m.TailX = ((double)Math.Abs(direction - 180) / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY = -1 * ((double)Math.Abs(direction - 90) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(180 - direction) / 100)
                    {
                        m.X = rand() % BufferWi;
                        m.Y = BufferHt;
                    }
                    else
                    {
                        m.X = 0;
                        m.Y = rand() % BufferHt;
                    }
                }
                else if (direction > 180 && direction <= 270)
                {
                    m.TailX = -1 * ((double)Math.Abs(direction - 180) / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY = -1 * ((double)Math.Abs(direction - 270) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(270 - direction) / 100)
                    {
                        m.X = BufferWi;
                        m.Y = rand() % BufferHt;
                    }
                    else
                    {
                        m.X = rand() % BufferWi;
                        m.Y = BufferHt;
                    }
                }
                else if (direction > 270 && direction <= 360)
                {
                    m.TailX = -1 * ((double)Math.Abs(direction - 360) / 90);
                    m.DeltaX = m.TailX * position;
                    m.TailY = ((double)Math.Abs(270 - direction) / 90);
                    m.DeltaY = m.TailY * position;
                    if (_random.NextDouble() >= (double)(360-direction)/100)
                    {
                        m.X = rand() % BufferWi;
                        m.Y = 0;
                    }
                    else
                    {
                        m.X = BufferWi;
                        m.Y = rand() % BufferHt;
                    }
                }

                if (MeteorEffect == MeteorsEffect.Explode)
                {
                    m.X = BufferWi/2;
                    m.Y = BufferHt/2;
                }
                else
                {
                    if (RandomMeteorPosition || frame < PixelCount)
                    {
                        m.X = rand() % BufferWi;
                        m.Y = (BufferHt - 1 - (rand() % tailStart));
                    }
                }
                m.DeltaXOrig = m.DeltaX;
                m.DeltaYOrig = m.DeltaY;

                switch (ColorType)
                {
                    case MeteorsColorType.Range: //Random two colors are selected from the list for each meteor.
                        m.Hsv =
                            SetRangeColor(HSV.FromRGB(Colors[rand()%colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame)*100)/100)),
                                HSV.FromRGB(Colors[rand()%colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame)*100)/100)));
                        break;
                    case MeteorsColorType.Palette: //All colors are used
                        m.Hsv = HSV.FromRGB(Colors[rand()%colorcnt].GetColorAt((GetEffectTimeIntervalPosition(frame)*100)/100));
                        break;
                    case MeteorsColorType.Gradient:
                        m.Color = rand() % colorcnt;
                        _gradientPosition = 100 / (double)tailLength / 100;
                        m.Hsv = HSV.FromRGB(Colors[m.Color].GetColorAt(0));
                        break;
                }
                m.HsvBrightness = RandomBrightness ? _random.NextDouble() * (1.0 - .25) + .25 : 1;
                _meteors.Add(m);
            }

            // render meteors
            foreach (MeteorClass meteor in _meteors)
            {
                meteor.DeltaX += meteor.DeltaXOrig;
                meteor.DeltaY += meteor.DeltaYOrig;
                int colorX = (meteor.X + Convert.ToInt32(meteor.DeltaX) - (BufferWi / 100));
                int colorY = (meteor.Y + Convert.ToInt32(meteor.DeltaY) + (BufferHt / 100));

                for (int ph = 0; ph < tailLength; ph++)
                {
                    switch (ColorType)
                    {
                        case MeteorsColorType.RainBow: //No user colors are used for Rainbow effect.
                            meteor.Hsv.H = (float) (rand()%1000)/1000.0f;
                            meteor.Hsv.S = 1.0f;
                            meteor.Hsv.V = 1.0f;
                            break;
                        case MeteorsColorType.Gradient:
                            meteor.Hsv = HSV.FromRGB(Colors[meteor.Color].GetColorAt(_gradientPosition*ph));
                            break;
                    }
                    hsv = meteor.Hsv;
                    hsv.V *= meteor.HsvBrightness;
                    hsv.V *= (float) (1.0 - ((double) ph/tailLength)*0.75);
                    //Adjusts the brightness based on the level curve
                    hsv.V = hsv.V * LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
                    var decPlaces = (int) (((decimal) (meteor.TailX*ph)%1)*100);
                    if (decPlaces <= 40 || decPlaces >= 60)
                        frameBuffer.SetPixel(colorX - (int) (Math.Round(meteor.TailX*ph)), colorY - (int) (Math.Round(meteor.TailY*ph)),
                            hsv);
                }
                if (colorX >= BufferWi + tailLength || colorY >= BufferHt + tailLength || colorX < 0 - tailLength ||
                    colorY < 0 - tailLength)
                {
                    meteor.Expired = true; //flags Meteors that have reached the end of the grid as expiried.
                    //	break;
                }
            }

            // delete old meteors
            int meteorNum = 0;
            while (meteorNum < _meteors.Count)
            {
                if (_meteors[meteorNum].Expired)
                {
                    _meteors.RemoveAt(meteorNum);
                }
                else
                {
                    meteorNum++;
                }
            }
        }
コード例 #5
0
ファイル: Meteors.cs プロジェクト: jmcadams/vplus
        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            if (eventToRender == 0) _meteors.Clear();

            var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight);
            var bufferWidth = buffer.GetLength(Utils.IndexColsOrWidth);
            var mspeed = eventToRender - _lastRenderedEvent;
            _lastRenderedEvent = eventToRender;

            // create new meteors
            var hsv = new HSV();
            var hsv0 = palette[0].ToHSV();
            var hsv1 = (palette.Length > 1 ? palette[1] : palette[0]).ToHSV();
            var colorcnt = palette.Length;
            var count = bufferWidth * tbCount.Value / 100;
            var tailLength = (bufferHeight < 10) ? tbTrailLength.Value / 10 : bufferHeight * tbTrailLength.Value / 100;
            if (tailLength < 1) tailLength = 1;
            var tailStart = bufferHeight - tailLength;
            if (tailStart < 1) tailStart = 1;
            for (var i = 0; i < count; i++) {
                var m = new MeteorClass {X = _random.Next() % bufferWidth, Y = bufferHeight - 1 - (_random.Next() % tailStart)};
                switch (cbType.SelectedIndex) {
                    case 1:
                        m.HSV = hsv0.CreateRangeTo(hsv1);
                        break;
                    case 2:
                        m.HSV = palette[_random.Next() % colorcnt].ToHSV() ;
                        break;
                }
                _meteors.Add(m);
            }

            // render meteors
            foreach (var meteor in _meteors) {
                {
                    for (var ph = 0; ph < tailLength; ph++) {
                        switch (cbType.SelectedIndex) {
                            case 0:
                                hsv.Hue = _random.Next() % 1000 / 1000.0f;
                                hsv.Saturation = 1.0f;
                                hsv.Value = 1.0f;
                                break;
                            default:
                                hsv.SetToHSV(meteor.HSV);
                                break;
                        }
                        hsv.Value *= (float)(1.0 - (double)ph / tailLength);
                        if (meteor.X < 0 || meteor.X >= bufferWidth || meteor.Y + ph < 0 || meteor.Y + ph >= bufferHeight) {
                            continue;
                        }
                        var y = meteor.Y + (chkBoxUp.Checked ? -ph : ph);
                        if (y >= 0 && y < bufferHeight) {
                            buffer[y, meteor.X] = hsv.ToColor();
                        }
                    }
                    meteor.Y += (chkBoxUp.Checked ? mspeed : -mspeed);
                }
            }
            // delete old meteors
            var meteorNum = 0;
            while (meteorNum < _meteors.Count) {
                if (_meteors[meteorNum].HasExpired(tailLength)) {
                    _meteors.RemoveAt(meteorNum);
                }
                else {
                    meteorNum++;
                }
            }
            return buffer;
        }
コード例 #6
0
        public Color[,] RenderEffect(Color[,] buffer, Color[] palette, int eventToRender)
        {
            if (eventToRender == 0)
            {
                _meteors.Clear();
            }

            var bufferHeight = buffer.GetLength(Utils.IndexRowsOrHeight);
            var bufferWidth  = buffer.GetLength(Utils.IndexColsOrWidth);
            var mspeed       = eventToRender - _lastRenderedEvent;

            _lastRenderedEvent = eventToRender;

            // create new meteors
            var hsv        = new HSV();
            var hsv0       = palette[0].ToHSV();
            var hsv1       = (palette.Length > 1 ? palette[1] : palette[0]).ToHSV();
            var colorcnt   = palette.Length;
            var count      = bufferWidth * tbCount.Value / 100;
            var tailLength = (bufferHeight < 10) ? tbTrailLength.Value / 10 : bufferHeight * tbTrailLength.Value / 100;

            if (tailLength < 1)
            {
                tailLength = 1;
            }
            var tailStart = bufferHeight - tailLength;

            if (tailStart < 1)
            {
                tailStart = 1;
            }
            for (var i = 0; i < count; i++)
            {
                var m = new MeteorClass {
                    X = _random.Next() % bufferWidth, Y = bufferHeight - 1 - (_random.Next() % tailStart)
                };
                switch (cbType.SelectedIndex)
                {
                case 1:
                    m.HSV = hsv0.CreateRangeTo(hsv1);
                    break;

                case 2:
                    m.HSV = palette[_random.Next() % colorcnt].ToHSV();
                    break;
                }
                _meteors.Add(m);
            }

            // render meteors
            foreach (var meteor in _meteors)
            {
                {
                    for (var ph = 0; ph < tailLength; ph++)
                    {
                        switch (cbType.SelectedIndex)
                        {
                        case 0:
                            hsv.Hue        = _random.Next() % 1000 / 1000.0f;
                            hsv.Saturation = 1.0f;
                            hsv.Value      = 1.0f;
                            break;

                        default:
                            hsv.SetToHSV(meteor.HSV);
                            break;
                        }
                        hsv.Value *= (float)(1.0 - (double)ph / tailLength);
                        if (meteor.X < 0 || meteor.X >= bufferWidth || meteor.Y + ph < 0 || meteor.Y + ph >= bufferHeight)
                        {
                            continue;
                        }
                        var y = meteor.Y + (chkBoxUp.Checked ? -ph : ph);
                        if (y >= 0 && y < bufferHeight)
                        {
                            buffer[y, meteor.X] = hsv.ToColor();
                        }
                    }
                    meteor.Y += (chkBoxUp.Checked ? mspeed : -mspeed);
                }
            }
            // delete old meteors
            var meteorNum = 0;

            while (meteorNum < _meteors.Count)
            {
                if (_meteors[meteorNum].HasExpired(tailLength))
                {
                    _meteors.RemoveAt(meteorNum);
                }
                else
                {
                    meteorNum++;
                }
            }
            return(buffer);
        }