コード例 #1
0
 public void TestAngleGeometry()
 {
     Assert.AreEqual(45, 0.AddToAngle(45));
     Assert.AreEqual(1, 360.AddToAngle(1));
     Assert.AreEqual(359, 0.AddToAngle(-1));
     Assert.AreEqual(359, 360.AddToAngle(-1));
     Assert.AreEqual(0, 0.DiffAngle(360));
     Assert.AreEqual(1, 1.DiffAngle(360));
     Assert.AreEqual(45, 0.DiffAngle(45));
     Assert.AreEqual(0, RectangularF.Create(0, 0, 1, 1).CalculateAngleTo(RectangularF.Create(1, 0, 1, 1)));
     Assert.AreEqual(45, RectangularF.Create(0, 0, 1, 1).CalculateAngleTo(RectangularF.Create(1, 1, 1, 1)));
     Assert.AreEqual(90, RectangularF.Create(0, 0, 1, 1).CalculateAngleTo(RectangularF.Create(0, 1, 1, 1)));
     Assert.AreEqual(135, RectangularF.Create(1, 0, 1, 1).CalculateAngleTo(RectangularF.Create(0, 1, 1, 1)));
     Assert.AreEqual(180, RectangularF.Create(1, 0, 1, 1).CalculateAngleTo(RectangularF.Create(0, 0, 1, 1)));
     Assert.AreEqual(225, RectangularF.Create(1, 1, 1, 1).CalculateAngleTo(RectangularF.Create(0, 0, 1, 1)));
     Assert.AreEqual(270, RectangularF.Create(1, 1, 1, 1).CalculateAngleTo(RectangularF.Create(1, 0, 1, 1)));
     Assert.AreEqual(315, RectangularF.Create(0, 1, 1, 1).CalculateAngleTo(RectangularF.Create(1, 0, 1, 1)));
 }
コード例 #2
0
ファイル: PerfTest.cs プロジェクト: BlackFrog1/PowerArgs
 private TestOptions BouncingBall()
 {
     return(new TestOptions()
     {
         InitTest = async() =>
         {
             var ball = Add(new Label()
             {
                 Text = "Bouncing ball".ToMagenta(), Y = 2, X = 1
             });
             await ball.AnimateAsync(new ConsoleControlAnimationOptions()
             {
                 Loop = Lifetime.Forever,
                 Duration = 1000,
                 Destination = () => RectangularF.Create((Width - ball.Width) - 1, ball.Y, ball.Width, ball.Height),
                 AutoReverse = true,
                 EasingFunction = Animator.EaseInOut,
             });
         }
     });
 }
コード例 #3
0
 public void TestDistanceGeometry()
 {
     Assert.AreEqual(0, RectangularF.Create(0, 0, 1, 1).CalculateDistanceTo(RectangularF.Create(0, 0, 1, 1)));
     Assert.AreEqual(0, RectangularF.Create(0, 0, 1, 1).CalculateDistanceTo(RectangularF.Create(1, 1, 1, 1)));
     Assert.AreEqual(1, RectangularF.Create(0, 0, 1, 1).CalculateDistanceTo(RectangularF.Create(2, 0, 1, 1)));
 }
コード例 #4
0
ファイル: PerfTest.cs プロジェクト: BlackFrog1/PowerArgs
        private async void Init()
        {
            var options = GetOptionsForArg();

            if (args.Mode == ConsoleMode.VirtualTerminal)
            {
                ConsoleProvider.Fancy = true;
            }

            if (args.Mode == ConsoleMode.Console)
            {
                ConsoleProvider.Fancy = false;
            }

            var mechanism = ConsoleProvider.Fancy == false ? "System.Console" : "VirtualTerminal";

            options.InitTest?.Invoke();
            var messagePanel = Add(new ConsolePanel()
            {
                Width = 45, Height = 3, Background = ConsoleColor.Red
            }).CenterBoth();
            var messageLabel = messagePanel.Add(new Label()
            {
                Text = "Waiting".ToConsoleString(fg: ConsoleColor.Black, bg: ConsoleColor.Red)
            }).CenterBoth();

            var now       = DateTime.Now;
            var paintsNow = ConsoleApp.Current.TotalPaints;

            while ((DateTime.Now - now).TotalSeconds < 3)
            {
                messageLabel.Text = $"{ConsoleApp.Current.TotalPaints- paintsNow} paints using {mechanism}".ToConsoleString(fg: ConsoleColor.Black, bg: ConsoleColor.Red, true);
                options.OnFrame?.Invoke();
                await Task.Yield();
            }

            var animationPanel = Add(new ConsolePanel()
            {
                Background = ConsoleColor.Green, Width = 45, Height = 3
            });

            var centerX = (int)Math.Round(Width / 2.0 - animationPanel.Width / 2.0);
            var targetY = (int)Math.Round((Height / 2.0 - animationPanel.Height / 2) - 5.0);

            animationPanel.X = centerX;
            animationPanel.Y = Height;
            var animationLabel = animationPanel.Add(new Label()
            {
                Text = "That's all folks".ToBlack(bg: ConsoleColor.Green)
            }).CenterBoth();
            await animationPanel.AnimateAsync(new ConsoleControlAnimationOptions()
            {
                Duration    = 1000,
                Destination = () => RectangularF.Create(centerX, targetY, animationPanel.Width, animationPanel.Height),
            });

            if (animationPanel.IsExpired == false && animationPanel.Parent?.IsExpired == false)
            {
                animationPanel.CenterHorizontally();
            }
        }