コード例 #1
0
        void ShowGrid()
        {
            int xOffset = 0;
            int yOffset = 0;
            int spacing = 15;

            for (int t = 0; t < 2000; t++)
            {
                display.Clear();

                for (int i = xOffset; i < display.Width; i += spacing)
                {
                    graphics.DrawVerticalLine(i, 0, (int)display.Height, true);
                }

                for (int j = yOffset; j < display.Height; j += spacing)
                {
                    graphics.DrawHorizontalLine(0, j, (int)display.Width, true);
                }

                xOffset = (xOffset + 1) % spacing;
                yOffset = (yOffset + 1) % spacing;

                display.Show();
            }
        }
コード例 #2
0
        void LineTest()
        {
            Console.WriteLine("Horizonal lines");

            graphics.Clear();

            for (int i = 1; i < 10; i++)
            {
                graphics.Stroke = i;
                graphics.DrawHorizontalLine(5, 20 * i, (int)(display.Width - 10), Color.Red);
            }
            graphics.Show();
            Thread.Sleep(1500);

            graphics.Clear();
            Console.WriteLine("Horizonal lines (negative)");
            for (int i = 1; i < 10; i++)
            {
                graphics.Stroke = i;
                graphics.DrawHorizontalLine((int)graphics.Width - 5, 20 * i, (int)(10 - graphics.Width), Color.Green);
            }
            graphics.Show();
            Thread.Sleep(1500);
            graphics.Clear();

            Console.WriteLine("Vertical lines");

            graphics.Clear();

            for (int i = 1; i < 10; i++)
            {
                graphics.Stroke = i;
                graphics.DrawVerticalLine(20 * i, 5, (int)(graphics.Height - 10), Color.Orange);
            }
            graphics.Show();
            Thread.Sleep(1500);
            graphics.Clear();

            Console.WriteLine("Vertical lines (negative)");
            for (int i = 1; i < 10; i++)
            {
                graphics.Stroke = i;
                graphics.DrawVerticalLine(20 * i, (int)(graphics.Height - 5), (int)(10 - graphics.Width), Color.Blue);
            }
            graphics.Show();
            Thread.Sleep(1500);
        }
コード例 #3
0
        int BenchLines(int num)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

            graphics.Stroke = 1;
            graphics.Clear(true);
            for (int i = 1; i < num; i++)
            {
                graphics.DrawLine(rand.Next(displayWidth), rand.Next(displayHeight), rand.Next(displayWidth), rand.Next(displayHeight), RandColor());
                graphics.Show();
            }
            int l1 = (int)stopWatch.Elapsed.TotalMilliseconds;

            Console.WriteLine($"{num} lines {l1}ms");
            stopWatch.Restart();

            graphics.Stroke = 2;
            graphics.Clear(true);
            for (int i = 1; i < num; i++)
            {
                graphics.DrawLine(rand.Next(displayWidth), rand.Next(displayHeight), rand.Next(displayWidth), rand.Next(displayHeight), RandColor());
                graphics.Show();
            }
            int l2 = (int)stopWatch.Elapsed.TotalMilliseconds;

            Console.WriteLine($"{num} 2x lines {l2}ms");
            stopWatch.Restart();

            graphics.Stroke = 3;
            graphics.Clear(true);
            for (int i = 1; i < num; i++)
            {
                graphics.DrawLine(rand.Next(displayWidth), rand.Next(displayHeight), rand.Next(displayWidth), rand.Next(displayHeight), RandColor());
                graphics.Show();
            }
            int l3 = (int)stopWatch.Elapsed.TotalMilliseconds;

            Console.WriteLine($"{num} 3x lines {l3}ms");
            stopWatch.Restart();

            graphics.Stroke = 2;
            graphics.Clear(true);
            for (int i = 1; i < num; i++)
            {
                graphics.DrawHorizontalLine(rand.Next(displayWidth), rand.Next(displayHeight), rand.Next(displayWidth), RandColor());
                graphics.Show();
            }
            int lh = (int)stopWatch.Elapsed.TotalMilliseconds;

            Console.WriteLine($"{num} horz lines {lh}ms");
            stopWatch.Restart();

            graphics.Stroke = 2;
            graphics.Clear(true);
            for (int i = 1; i < num; i++)
            {
                graphics.DrawVerticalLine(rand.Next(displayWidth), rand.Next(displayHeight), rand.Next(displayWidth), RandColor());
                graphics.Show();
            }
            int lv = (int)stopWatch.Elapsed.TotalMilliseconds;

            Console.WriteLine($"{num} vert lines {lh}ms");
            stopWatch.Restart();

            stopWatch.Stop();

            return(l1 + l2 + l3 + lh + lv);
        }