当前位置: 首页>>代码示例>>C#>>正文


C# ColorGradient.SetEffect方法代码示例

本文整理汇总了C#中ColorGradient.SetEffect方法的典型用法代码示例。如果您正苦于以下问题:C# ColorGradient.SetEffect方法的具体用法?C# ColorGradient.SetEffect怎么用?C# ColorGradient.SetEffect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ColorGradient的用法示例。


在下文中一共展示了ColorGradient.SetEffect方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SplashScreen

        public SplashScreen()
            : base(80, 25)
        {
            IsVisible = false;

            // Setup the console text background
            string textTemplate = "sole SadCon";
            System.Text.StringBuilder text = new System.Text.StringBuilder(2200);

            for (int i = 0; i < CellData.Width * CellData.Height; i++)
            {
                text.Append(textTemplate);
            }
            this.CellData.Print(0, 0, text.ToString(), Color.Black, Color.Transparent);

            // Load the logo
            System.IO.Stream imageStream = System.IO.File.OpenRead("sad.png");
            var image = Texture2D.FromStream(Engine.Device, imageStream);
            imageStream.Dispose();

            // Configure the logo
            _consoleImage = new CellsRenderer(new CellSurface(image.Width, image.Height), this.Batch);
            _consoleImage.Position = new Point(CellData.Width / 2 - image.Width / 2, -1);
            image.DrawImageToSurface(_consoleImage.CellData, new Point(0,0), true);
            _consoleImage.Tint = Color.Black;

            // Configure the animations
            _animation = new InstructionSet();
            _animation.Instructions.AddLast(new Wait() { Duration = 0.3f });

            // Animation to move the angled gradient spotlight effect.
            var moveGradientInstruction = new CodeInstruction();
            moveGradientInstruction.CodeCallback = (inst) =>
                {
                    _x += 1;

                    if (_x > _cellData.Width + 50)
                    {
                        inst.IsFinished = true;
                    }

                    Color[] colors = new Color[] { Color.Black, Color.DarkBlue, Color.White, Color.DarkBlue, Color.Black };
                    float[] colorStops = new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f };

                    Algorithms.GradientFill(CellSize, new Point(_x, 12), 10, 45, new Rectangle(0, 0, CellData.Width, CellData.Height), new ColorGradient(colors, colorStops), _cellData.SetForeground);
                };
            _animation.Instructions.AddLast(moveGradientInstruction);

            // Animation to clear the SadConsole text.
            _animation.Instructions.AddLast(new CodeInstruction() { CodeCallback = (i) => { _cellData.Fill(Color.Black, Color.Transparent, 0, null); i.IsFinished = true; } });

            // Animation for the logo text.
            var logoText = new ColorGradient(new Color[] { Color.Purple, Color.Yellow }, new float[] { 0.0f, 1f }).ToColoredString("[| Powered by SadConsole |]");
            logoText.SetEffect(new SadConsole.Effects.Fade() { DestinationForeground = Color.Blue, FadeForeground = true, FadeDuration = 1f, Repeat = false, RemoveOnFinished = true, Permanent = true, CloneOnApply = true });
            _animation.Instructions.AddLast(new DrawString(this) { Position = new Point(26, this.CellData.Height - 1), Text = logoText, TotalTimeToPrint = 1f, UseConsolesCursorToPrint = false });

            // Animation for fading in the logo picture.
            _animation.Instructions.AddLast(new FadeCellRenderer(_consoleImage, new ColorGradient(Color.Black, Color.Transparent), new TimeSpan(0, 0, 0, 0, 2000)));

            // Animation to blink SadConsole in the logo text
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                    {
                        SadConsole.Effects.Fade fadeEffect = new SadConsole.Effects.Fade();
                        fadeEffect.AutoReverse = true;
                        fadeEffect.DestinationForeground = new ColorGradient(Color.Blue, Color.Yellow);
                        fadeEffect.FadeForeground = true;
                        fadeEffect.Repeat = true;
                        fadeEffect.FadeDuration = 0.7f;

                        List<Cell> cells = new List<Cell>();
                        for (int index = 0; index < 10; index++)
                        {
                            var point = new Point(26, this.CellData.Height - 1).ToIndex(this.CellData.Width) + 14 + index;
                            cells.Add(_cellData[point]);
                        }

                        _cellData.SetEffect(cells, fadeEffect);
                        i.IsFinished = true;
                    }
            });
            
            // Animation to delay, keeping the logo and all on there for 2 seconds, then destroy itself.
            _animation.Instructions.AddLast(new Wait() { Duration = 2.5f });
            _animation.Instructions.AddLast(new FadeCellRenderer(this, new ColorGradient(Color.Transparent, Color.Black), new TimeSpan(0, 0, 0, 0, 2000)));
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                {
                    if (this.Parent != null)
                        this.Parent.Remove(this);

                    if (SplashCompleted != null)
                        SplashCompleted();
                }
            });
        }
开发者ID:drock07,项目名称:SadConsole,代码行数:98,代码来源:SplashScreen.cs


注:本文中的ColorGradient.SetEffect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。