Esempio n. 1
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            _intervalPos       = (float)GetEffectTimeIntervalPosition(frame);
            _intervalPosFactor = _intervalPos * 100;

            _radius         = CalculateSize(_intervalPosFactor);
            _centerSpeed    = CalculateCenterSpeed(_intervalPosFactor);
            _speedVariation = CalculateSpeedVariation(_intervalPosFactor);
            _level          = LevelCurve.GetValue(_intervalPosFactor) / 100;
            int   maxRandomTime    = CalculateRandomMax(_intervalPosFactor);
            Color inverseBackColor = BackgroundColor.GetColorAt(_intervalPos);

            double minSpeed = _centerSpeed - (_speedVariation / 2);
            double maxSpeed = _centerSpeed + (_speedVariation / 2);

            _ballCount = CalculateBallCount(_intervalPosFactor);

            // Create new Balls and add balls due to increase in ball count curve.
            CreateBalls(minSpeed, maxSpeed, maxRandomTime);

            // Update Ball location, radius and speed.
            UpdateBalls(minSpeed, maxSpeed, maxRandomTime);

            //Remove Excess Balls due to BallCount Curve.
            RemoveBalls();

            //Iterate through all grid locations.
            for (int y = 0; y < _bufferHt; y++)
            {
                for (int x = 0; x < _bufferWi; x++)
                {
                    CalculatePixel(x, y, frameBuffer, inverseBackColor);
                }
            }
        }
Esempio n. 2
0
        protected override void RenderEffectByLocation(int numFrames, PixelLocationFrameBuffer frameBuffer)
        {
            var nodes = frameBuffer.ElementLocations.OrderBy(x => x.Y).ThenBy(x => x.X).GroupBy(x => x.Y);

            for (int frame = 0; frame < numFrames; frame++)
            {
                frameBuffer.CurrentFrame = frame;
                _intervalPos             = (float)GetEffectTimeIntervalPosition(frame);
                _intervalPosFactor       = _intervalPos * 100;

                _radius         = CalculateSize(_intervalPosFactor);
                _centerSpeed    = CalculateCenterSpeed(_intervalPosFactor);
                _speedVariation = CalculateSpeedVariation(_intervalPosFactor);
                _level          = LevelCurve.GetValue(_intervalPosFactor) / 100;
                int   maxRandomTime    = CalculateRandomMax(_intervalPosFactor);
                Color inverseBackColor = BackgroundColor.GetColorAt(_intervalPos);

                double minSpeed = _centerSpeed - (_speedVariation / 2);
                double maxSpeed = _centerSpeed + (_speedVariation / 2);

                _ballCount = CalculateBallCount(_intervalPosFactor);

                // Create new Balls and add balls due to increase in ball count curve.
                CreateBalls(minSpeed, maxSpeed, maxRandomTime);

                // Update Ball location, radius and speed.
                UpdateBalls(minSpeed, maxSpeed, maxRandomTime);

                //Remove Excess Balls due to BallCount Curve.
                RemoveBalls();

                //Iterate through all grid locations.
                foreach (IGrouping <int, ElementLocation> elementLocations in nodes)
                {
                    foreach (var elementLocation in elementLocations)
                    {
                        CalculatePixel(elementLocation.X, elementLocation.Y, frameBuffer, inverseBackColor);
                    }
                }
            }
        }
Esempio n. 3
0
        protected override void RenderEffect(int frame, IPixelFrameBuffer frameBuffer)
        {
            double level                = LevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
            double blendLevel           = BlendCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;
            double backgroundLevelCurve = BackgroundLevelCurve.GetValue(GetEffectTimeIntervalPosition(frame) * 100) / 100;

            int   x, y, mod, b;
            float V;
            int   cycleLen        = frame * Speed;
            int   pixelsPerBranch = (int)(0.5 + (double)BufferHt / Branches);

            if (pixelsPerBranch == 0)
            {
                pixelsPerBranch = 1;
            }

            if (frame == _xLimit)
            {
                _treeWidth = 0;
                _xLimit   += BufferWi;
            }
            _treeWidth++;

            for (y = 0; y < BufferHt; y++)
            {
                for (x = 0; x < BufferWi; x++)
                {
                    mod = y % pixelsPerBranch;
                    if (mod == 0)
                    {
                        mod = pixelsPerBranch;
                    }
                    V = ToggleBlend                     //Fade between branches
                                                ? (float)(1 - (1.0 * mod / pixelsPerBranch) * (1 - blendLevel))
                                                : (float)((1.0 * mod / pixelsPerBranch) * (blendLevel));

                    HSV hsv = HSV.FromRGB(BackgroundColor.GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                    hsv.V = backgroundLevelCurve * V;                     // we have now set the color for the background tree

                    //   $orig_rgbval=$rgb_val;
                    Branch = (int)((y - 1) / pixelsPerBranch);
                    if (_branchColor >= Colors.Count || Branch == 0)
                    {
                        _branchColor = 0;
                    }
                    _row = pixelsPerBranch - mod;                     // now row=0 is bottom of branch, row=1 is one above bottom
                    //  mod = which pixel we are in the branch
                    //	mod=1,row=pixels_per_branch-1   top picrl in branch
                    //	mod=2, second pixel down into branch
                    //	mod=pixels_per_branch,row=0  last pixel in branch
                    //
                    //	row = 0, the $p is in the bottom row of tree
                    //	row =1, the $p is in second row from bottom
                    b = (int)((cycleLen) / BufferWi) % Branches;                     // what branch we are on based on frame #
                    //
                    //	b = 0, we are on bottomow row of tree during frames 1 to BufferWi
                    //	b = 1, we are on second row from bottom, frames = BufferWi+1 to 2*BufferWi
                    //	b = 2, we are on third row from bottome, frames - 2*BufferWi+1 to 3*BufferWi

                    M = (x % 6);
                    // m=0, 1sr strand
                    // m=1, 2nd strand
                    // m=5, last strand in 6 strand pattern

                    switch (ColorType)
                    {
                    case TreeColorType.Twinkle:
                        _colorIdx = _random.Next(0, Colors.Count);
                        break;

                    case TreeColorType.AlternatePixel:
                        _colorIdx = (x % Colors.Count);
                        break;

                    case TreeColorType.Static:
                        _colorIdx = _branchColor;
                        break;

                    case TreeColorType.Alternate:
                        break;
                    }

                    switch (BranchDirection)
                    {
                    case TreeBranchDirection.UpRight:
                    case TreeBranchDirection.DownRight:
                    case TreeBranchDirection.UpLeft:
                    case TreeBranchDirection.DownLeft:
                        if (Branch <= b && x <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3)))))))
                        {
                            hsv = HSV.FromRGB(Colors[_colorIdx].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                        }
                        break;

                    case TreeBranchDirection.Up:
                    case TreeBranchDirection.Down:
                        if (Branch <= b &&
                            (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3)))))))
                        {
                            hsv = HSV.FromRGB(Colors[_colorIdx].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                        }
                        break;

                    case TreeBranchDirection.Left:
                        if ((BufferWi - x) <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3)))))))
                        {
                            hsv = HSV.FromRGB(Colors[_colorIdx].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                        }
                        break;

                    case TreeBranchDirection.Alternate:
                        if (Branch % 2 != 0)
                        {
                            if ((BufferWi - x) <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3)))))))
                            {
                                hsv = HSV.FromRGB(Colors[_colorIdx].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                            }
                        }
                        else
                        {
                            if (x <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3)))))))
                            {
                                hsv = HSV.FromRGB(Colors[_colorIdx].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                            }
                        }
                        break;

                    case TreeBranchDirection.Right:
                        if (x <= _treeWidth && (((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3)))))))
                        {
                            hsv = HSV.FromRGB(Colors[_colorIdx].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                        }
                        break;

                    case TreeBranchDirection.None:
                        if (((((_row == 3 && (M == 0 || M == 5)) || ((_row == 2 && (M == 1 || M == 4)) || ((_row == 1 && (M == 2 || M == 3))))))))
                        {
                            hsv = HSV.FromRGB(Colors[_colorIdx].GetColorAt((GetEffectTimeIntervalPosition(frame) * 100) / 100));
                        }
                        break;
                    }

                    hsv.V = hsv.V * level;                   //adjusts overall intensity
                    switch (BranchDirection)
                    {
                    case TreeBranchDirection.Down:
                    case TreeBranchDirection.DownRight:
                        frameBuffer.SetPixel(x, BufferHt - y, hsv);
                        break;

                    case TreeBranchDirection.UpLeft:
                        frameBuffer.SetPixel(BufferWi - x, y, hsv);
                        break;

                    case TreeBranchDirection.DownLeft:
                        frameBuffer.SetPixel(BufferWi - x, BufferHt - y, hsv);
                        break;

                    default:
                        frameBuffer.SetPixel(x, y, hsv);
                        break;
                    }
                }
                _colorIdx = (Branch % Colors.Count);
            }
        }