示例#1
0
        int BenchTriangle(int num)
        {
            Stopwatch stopWatch = new Stopwatch();

            stopWatch.Start();

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

            Console.WriteLine($"{num} Triangles {empty}ms");
            stopWatch.Restart();

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

            Console.WriteLine($"{num} Triangles Filled {filled}ms");
            stopWatch.Stop();

            return(empty + filled);
        }
示例#2
0
        void TestDisplay()
        {
            //force a collection
            GC.Collect();

            Console.WriteLine("Draw");


            for (int i = 0; i < 30; i++)
            {
                display.DrawPixel(i, 120 + i, true);
                display.DrawPixel(30 + i, 120 + i, true);
                display.DrawPixel(60 + i, 120 + i, true);
            }

            // Draw with Display Graphics Library
            graphics.CurrentFont = new Font8x8();
            graphics.Clear();
            graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red);
            graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false);
            graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false);

            graphics.DrawText(5, 5, "Meadow F7 SPI", Color.White);
            graphics.Show();
        }
示例#3
0
        void ShapeTest()
        {
            graphics.Clear();

            graphics.DrawCircle(60, 60, 20, Color.Purple);
            graphics.DrawRectangle(10, 10, 30, 60, Color.Red);
            graphics.DrawTriangle(20, 20, 10, 70, 60, 60, Color.Green);

            graphics.DrawCircle(90, 60, 20, Color.Cyan, true);
            graphics.DrawRectangle(100, 100, 30, 10, Color.Yellow, true);
            graphics.DrawTriangle(120, 20, 110, 70, 160, 60, Color.Pink, true);

            graphics.DrawLine(10, 120, 110, 130, Color.SlateGray);

            graphics.Show();
        }
示例#4
0
        void TestILI9163()
        {
            Console.WriteLine("Clear display");

            // Drawing natively in the display
            display.ClearScreen(250);

            Console.WriteLine("Draw");

            for (int i = 0; i < 30; i++)
            {
                display.DrawPixel(i, i, true);
                display.DrawPixel(30 + i, i, true);
                display.DrawPixel(60 + i, i, true);
            }

            Console.WriteLine("Show");

            display.Show();

            Console.WriteLine("Show complete");

            // Drawing with Display Graphics Library
            graphics.CurrentFont = new Font8x8();
            graphics.Clear();
            graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red);
            graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, false);
            graphics.DrawCircle(50, 50, 40, Meadow.Foundation.Color.Blue, false);
            graphics.DrawText(5, 5, "Meadow F7 SPI");
            graphics.Show();
        }
示例#5
0
        void TestST7565()
        {
            Console.WriteLine("TestST7565...");

            // Drawing with Display Graphics Library
            graphics.CurrentFont = new Font8x8();
            graphics.Clear();
            graphics.DrawTriangle(10, 10, 50, 50, 10, 50, Meadow.Foundation.Color.Red);
            graphics.DrawRectangle(20, 15, 40, 20, Meadow.Foundation.Color.Yellow, true);
            graphics.DrawText(5, 5, "ST7565");
            graphics.Show();
        }
示例#6
0
        void ColorFontTest()
        {
            graphics.CurrentFont = new Font8x12();

            graphics.Clear();

            graphics.DrawTriangle(120, 20, 200, 100, 120, 100, Meadow.Foundation.Color.Red, false);

            graphics.DrawRectangle(140, 30, 40, 90, Meadow.Foundation.Color.Yellow, false);

            graphics.DrawCircle(160, 80, 40, Meadow.Foundation.Color.Cyan, false);

            int indent  = 5;
            int spacing = 14;
            int y       = indent;

            graphics.DrawText(indent, y, "Meadow + SSD1327!!");

            graphics.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red);

            graphics.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple);

            graphics.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet);

            graphics.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue);

            graphics.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan);

            graphics.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen);

            graphics.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow);

            graphics.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow);

            graphics.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange);

            graphics.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown);

            graphics.Show();

            Console.WriteLine("Show complete");
        }
示例#7
0
        public MeadowApp()
        {
            Console.WriteLine("TftSpi sample");
            Console.WriteLine("Create Spi bus");

            var config = new SpiClockConfiguration(6000, SpiClockConfiguration.Mode.Mode3);

            spiBus = Device.CreateSpiBus(Device.Pins.SCK, Device.Pins.MOSI, Device.Pins.MISO, config);

            Console.WriteLine("Create display driver instance");

            display = new ST7789(device: Device, spiBus: spiBus,
                                 chipSelectPin: Device.Pins.D02,
                                 dcPin: Device.Pins.D01,
                                 resetPin: Device.Pins.D00,
                                 width: 240, height: 240);

            Console.WriteLine("Create graphics lib");

            var graphicsLib = new GraphicsLibrary(display);

            graphicsLib.CurrentFont = new Font8x12();

            graphicsLib.Clear();

            graphicsLib.DrawTriangle(120, 20, 200, 100, 120, 100, Meadow.Foundation.Color.Red, false);

            graphicsLib.DrawRectangle(140, 30, 40, 90, Meadow.Foundation.Color.Yellow, false);

            graphicsLib.DrawCircle(160, 80, 40, Meadow.Foundation.Color.Cyan, false);

            int indent  = 5;
            int spacing = 14;
            int y       = indent;

            graphicsLib.DrawText(indent, y, "Meadow F7 SPI ST7789!!");

            graphicsLib.DrawText(indent, y += spacing, "Red", Meadow.Foundation.Color.Red);

            graphicsLib.DrawText(indent, y += spacing, "Purple", Meadow.Foundation.Color.Purple);

            graphicsLib.DrawText(indent, y += spacing, "BlueViolet", Meadow.Foundation.Color.BlueViolet);

            graphicsLib.DrawText(indent, y += spacing, "Blue", Meadow.Foundation.Color.Blue);

            graphicsLib.DrawText(indent, y += spacing, "Cyan", Meadow.Foundation.Color.Cyan);

            graphicsLib.DrawText(indent, y += spacing, "LawnGreen", Meadow.Foundation.Color.LawnGreen);

            graphicsLib.DrawText(indent, y += spacing, "GreenYellow", Meadow.Foundation.Color.GreenYellow);

            graphicsLib.DrawText(indent, y += spacing, "Yellow", Meadow.Foundation.Color.Yellow);

            graphicsLib.DrawText(indent, y += spacing, "Orange", Meadow.Foundation.Color.Orange);

            graphicsLib.DrawText(indent, y += spacing, "Brown", Meadow.Foundation.Color.Brown);


            graphicsLib.Show();

            Console.WriteLine("Show complete");
        }
示例#8
0
        void AdjustTemperatureScreen()
        {
            Console.WriteLine("MainScreen()...");

            float temperature = 23.5f;

            graphics.Stroke = 1;
            graphics.DrawRectangle(0, 0, (int)st7789.Width, (int)st7789.Height, Color.White);
            graphics.DrawRectangle(5, 5, (int)st7789.Width - 10, (int)st7789.Height - 10, Color.White);
            graphics.Show();

            Console.WriteLine("1...");

            graphics.DrawCircle((int)st7789.Width / 2, (int)st7789.Height / 2, (int)(st7789.Width / 2) - 10, Color.White, true);
            graphics.Show();

            Console.WriteLine("2...");

            graphics.DrawTriangle(
                x0: (int)(st7789.Width * 0.35),
                y0: (int)(st7789.Height * 0.30),
                x1: (int)(st7789.Width * 0.5),
                y1: (int)(st7789.Height * 0.15),
                x2: (int)(st7789.Width * 0.65),
                y2: (int)(st7789.Height * 0.30),
                color: Color.Black,
                filled: true);

            graphics.DrawTriangle(
                x0: (int)(st7789.Width * 0.35),
                y0: (int)(st7789.Height * 0.70),
                x1: (int)(st7789.Width * 0.5),
                y1: (int)(st7789.Height * 0.85),
                x2: (int)(st7789.Width * 0.65),
                y2: (int)(st7789.Height * 0.70),
                color: Color.Black,
                filled: true);
            graphics.Show();

            graphics.CurrentFont = new Font12x20();
            graphics.DrawText(
                (int)(st7789.Width - temperature.ToString().Length * 24) / 2,
                (int)(st7789.Height * 0.50) - 20,
                temperature.ToString("##.##"), Color.Black, GraphicsLibrary.ScaleFactor.X2);
            graphics.Show();

            Console.WriteLine("3...");

            for (int i = 1; i < 10; i++)
            {
                graphics.DrawText(
                    (int)(st7789.Width - temperature.ToString().Length * 24) / 2,
                    (int)(st7789.Height * 0.50) - 20,
                    temperature.ToString("##.##"), Color.White, GraphicsLibrary.ScaleFactor.X2);

                Console.WriteLine($"4... {temperature}");
                temperature++;

                graphics.DrawText(
                    (int)(st7789.Width - temperature.ToString().Length * 24) / 2,
                    (int)(st7789.Height * 0.50) - 20,
                    temperature.ToString("##.##"), Color.Black, GraphicsLibrary.ScaleFactor.X2);
                graphics.Show();

                Thread.Sleep(1000);
            }
        }