示例#1
0
文件: Tree.cs 项目: starry-au/vixen
        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);
            }
        }