Beispiel #1
0
        void SensorChannelStatusesChanged(object sender, ChannelStatusChangedEventArgs e)
        {
            graphics.Clear();
            graphics.Stroke = 1;

            for (int i = 0; i < e.ChannelStatus.Count; i++)
            {
                int numpadIndex = 0;
                for (int columns = 0; columns < 3; columns++)
                {
                    for (int rows = 3; rows >= 0; rows--)
                    {
                        if (numpadIndex == i)
                        {
                            if (e.ChannelStatus[(Mpr121.Channels)i])
                            {
                                graphics.DrawRectangle(columns * 57 + 38, rows * 57 + 10, 51, 51, Meadow.Foundation.Color.Cyan, true);
                            }
                            else
                            {
                                graphics.DrawRectangle(columns * 57 + 38, rows * 57 + 10, 51, 51, true);
                            }
                        }
                        numpadIndex++;
                    }
                }
            }

            graphics.Show();
        }
Beispiel #2
0
 void DrawTitleAndFrame()
 {
     graphics.Clear();
     graphics.DrawRectangle(0, 0, 240, 240);
     graphics.DrawText(24, 15, "Morse Code Coach");
     graphics.DrawHorizontalLine(24, 41, 196, Color.White);
     graphics.Show();
 }
        void DrawShapes()
        {
            Random rand = new Random();

            graphics.Clear(true);

            int radius  = 10;
            int originX = displayWidth / 2;
            int originY = displayHeight / 2;

            for (int i = 1; i < 5; i++)
            {
                graphics.DrawCircle
                (
                    centerX: originX,
                    centerY: originY,
                    radius: radius,
                    color: Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255))
                );
                graphics.Show();
                radius += 30;
            }

            int sideLength = 30;

            for (int i = 1; i < 5; i++)
            {
                graphics.DrawRectangle
                (
                    x: (displayWidth - sideLength) / 2,
                    y: (displayHeight - sideLength) / 2,
                    width: sideLength,
                    height: sideLength,
                    color: Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255))
                );
                graphics.Show();
                sideLength += 60;
            }

            graphics.DrawLine(0, displayHeight / 2, displayWidth, displayHeight / 2,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.DrawLine(displayWidth / 2, 0, displayWidth / 2, displayHeight,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.DrawLine(0, 0, displayWidth, displayHeight,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.DrawLine(0, displayHeight, displayWidth, 0,
                              Color.FromRgb(rand.Next(128, 255), rand.Next(128, 255), rand.Next(128, 255)));
            graphics.Show();

            //Thread.Sleep(5000);
        }
Beispiel #4
0
        void LoadScreen()
        {
            Console.WriteLine("LoadScreen...");

            graphics.Clear(true);

            graphics.Stroke = 1;
            graphics.DrawRectangle(
                x: 0,
                y: 0,
                width: graphics.Width,
                height: graphics.Height,
                color: Color.White);
            graphics.DrawRectangle(
                x: 5,
                y: 5,
                width: graphics.Width - 10,
                height: graphics.Height - 10,
                color: Color.White);

            graphics.DrawCircle(
                centerX: graphics.Width / 2,
                centerY: graphics.Height / 2,
                radius: (graphics.Width / 2) - 10,
                color: Color.FromHex("#EF7D3B"),
                filled: true);

            DisplayJPG(55, 40);

            graphics.CurrentFont = new Font8x12();

            string textMotion = "MOTION";

            graphics.DrawText(
                (graphics.Width - textMotion.Length * 16) / 2,
                140,
                textMotion,
                Color.Black,
                ScaleFactor.X2);

            string textDetector = "DETECTOR";

            graphics.DrawText(
                (graphics.Width - textDetector.Length * 16) / 2,
                165,
                textDetector,
                Color.Black,
                ScaleFactor.X2);

            graphics.Show();
        }
Beispiel #5
0
        void UpdateImage(int index, int xOffSet, int yOffSet)
        {
            var jpgData = LoadResource($"level_{index}.jpg");
            var decoder = new JpegDecoder();
            var jpg     = decoder.DecodeJpeg(jpgData);

            int  x = 0;
            int  y = 0;
            byte r, g, b;

            graphics.DrawRectangle(0, 0, 240, 208, Color.White, true);

            for (int i = 0; i < jpg.Length; i += 3)
            {
                r = jpg[i];
                g = jpg[i + 1];
                b = jpg[i + 2];

                graphics.DrawPixel(x + xOffSet, y + yOffSet, Color.FromRgb(r, g, b));

                x++;
                if (x % decoder.Width == 0)
                {
                    y++;
                    x = 0;
                }
            }

            graphics.Show();
        }
        void RotaryYClicked(object sender, EventArgs e)
        {
            x = y = 120;

            graphics.DrawRectangle(0, 0, 240, 240, Color.White, true);
            graphics.DrawPixel(x, y, Color.Red);
            graphics.Show();
        }
 void DisplayText(string text, int x = 12)
 {
     graphics.Clear();
     graphics.CurrentFont = new Font8x12();
     graphics.DrawRectangle(0, 0, 128, 32);
     graphics.DrawText(x, 12, text);
     graphics.Show();
 }
Beispiel #8
0
        public void ShowSplashScreen()
        {
            canvas.CurrentFont = new Font4x6();

            canvas.Clear();
            canvas.DrawRectangle(0, 0, canvas.Width, canvas.Height);
            canvas.DrawText(canvas.Width / 2, 2, "OnAir", alignment: TextAlignment.Center);
            canvas.Show();

            canvas.CurrentFont = new Font4x8();
        }
        public void UpdateDisplay(WeatherViewModel model)
        {
            graphics.Clear();

            graphics.DrawRectangle(0, 0, graphics.Width, graphics.Height, Color.White, true);

            DisplayJPG(model.WeatherCode, 5, 5);

            graphics.DrawText(134, 143, "Outdoor", Color.Black);

            string outdoorTemp = model.OutdoorTemperature.ToString("00°C");

            graphics.DrawText(128, 178, outdoorTemp, Color.Black, ScaleFactor.X2);

            graphics.DrawText(23, 143, "Indoor", Color.Black);

            string indoorTemp = model.IndoorTemperature.ToString("00°C");

            graphics.DrawText(11, 178, indoorTemp, Color.Black, ScaleFactor.X2);

            graphics.Show();
        }
Beispiel #10
0
        void DrawTetrisField()
        {
            int xIndent = 8;
            int yIndent = 12;

            graphics.DrawText(xIndent, 0, $"Lines: {game.LinesCleared}");

            graphics.DrawRectangle(6, 10, 52, 112);

            //draw current piece
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (game.IsPieceLocationSet(i, j))
                    {
                        //  graphics.DrawPixel(i, j);
                        graphics.DrawRectangle((game.CurrentPiece.X + i) * BLOCK_SIZE + xIndent,
                                               (game.CurrentPiece.Y + j) * BLOCK_SIZE + yIndent,
                                               BLOCK_SIZE + 1, BLOCK_SIZE, true, true);//+1 hack until we fix the graphics lib
                    }
                }
            }

            //draw gamefield
            for (int i = 0; i < game.Width; i++)
            {
                for (int j = 0; j < game.Height; j++)
                {
                    if (game.IsGameFieldSet(i, j))
                    {
                        graphics.DrawRectangle((i) * BLOCK_SIZE + xIndent,
                                               (j) * BLOCK_SIZE + yIndent,
                                               BLOCK_SIZE + 1, BLOCK_SIZE, true, true);//+1 hack until we fix the graphics lib
                    }
                }
            }
        }
        void DrawBackground()
        {
            //draw docks
            for (int i = 0; i < 5; i++)
            {
                graphics.DrawRectangle(10 + 24 * i, 0, 12, 8, true, false);

                if (i < frogger.FrogsHome)
                {
                    DrawFrog(12 + 24 * i, 0, 1);
                }
            }

            //draw water
            //graphics.DrawRectangle(0, cellSize, 128, cellSize * 3, true, true);
        }
        public MeadowApp()
        {
            var onboardLed = new RgbPwmLed(
                device: Device,
                redPwmPin: Device.Pins.OnboardLedRed,
                greenPwmPin: Device.Pins.OnboardLedGreen,
                bluePwmPin: Device.Pins.OnboardLedBlue);

            onboardLed.SetColor(Color.Red);

            x = y = 120;

            var config = new SpiClockConfiguration(
                speed: new Frequency(48000, Frequency.UnitType.Kilohertz),
                mode: SpiClockConfiguration.Mode.Mode3);
            var spiBus = Device.CreateSpiBus(
                clock: Device.Pins.SCK,
                copi: Device.Pins.MOSI,
                cipo: Device.Pins.MISO,
                config: config);
            var st7789 = new St7789(
                device: Device,
                spiBus: spiBus,
                chipSelectPin: null,
                dcPin: Device.Pins.D01,
                resetPin: Device.Pins.D00,
                width: 240, height: 240);

            graphics = new MicroGraphics(st7789);
            graphics.Clear(true);
            graphics.DrawRectangle(0, 0, 240, 240, Color.White, true);
            graphics.DrawPixel(x, y, Color.Red);
            graphics.Show();

            rotaryX = new RotaryEncoderWithButton(Device,
                                                  Device.Pins.A00, Device.Pins.A01, Device.Pins.A02);
            rotaryX.Rotated += RotaryXRotated;

            rotaryY = new RotaryEncoderWithButton(Device,
                                                  Device.Pins.D02, Device.Pins.D03, Device.Pins.D04);
            rotaryY.Rotated += RotaryYRotated;
            rotaryY.Clicked += RotaryYClicked;

            onboardLed.SetColor(Color.Green);
        }
        void AnalogTemperatureTemperatureUpdated(object sender, IChangeResult <Meadow.Units.Temperature> e)
        {
            graphics.DrawRectangle(
                x: 48,
                y: 160,
                width: 144,
                height: 40,
                color: colors[colors.Length - 1],
                filled: true);

            graphics.DrawText(
                x: 48, y: 160,
                text: $"{e.New.Celsius:00.0}°C",
                color: Color.White,
                scaleFactor: ScaleFactor.X2);

            graphics.Show();
        }
Beispiel #14
0
        public DisplayController(St7789 display)
        {
            graphics             = new MicroGraphics(display);
            graphics.CurrentFont = new Font12x20();
            graphics.Stroke      = 3;

            graphics.Clear();

            graphics.DrawRectangle(0, 0, 240, 240, Color.White, true);

            string plant   = "Plant";
            string monitor = "Monitor";

            graphics.CurrentFont = new Font12x16();
            graphics.DrawText((240 - (plant.Length * 24)) / 2, 80, plant, Color.Black, ScaleFactor.X2);
            graphics.DrawText((240 - (monitor.Length * 24)) / 2, 130, monitor, Color.Black, ScaleFactor.X2);

            graphics.Show();
        }
        void DrawGame()
        {
            //draw gameboard
            graphics.DrawRectangle(xStart, yStart, CellSize * connectGame.Width + 1, CellSize * connectGame.Height + 1, Color.DarkBlue, true);
            graphics.DrawRectangle(xStart, yStart, CellSize * connectGame.Width + 1, CellSize * connectGame.Height + 1, Color.Blue, false);

            for (int i = 1; i < 7; i++)
            {
                graphics.DrawLine(xStart + CellSize * i,
                                  yStart,
                                  xStart + CellSize * i,
                                  yStart + CellSize * 6 + 1,
                                  Color.Blue);
            }

            for (int j = 1; j < 6; j++)
            {
                graphics.DrawLine(xStart,
                                  yStart + j * CellSize,
                                  CellSize * connectGame.Width + xStart,
                                  yStart + j * CellSize,
                                  Color.Blue);
            }

            for (int x = 0; x < connectGame.Width; x++)
            {
                for (int y = 0; y < connectGame.Height; y++)
                {
                    if (connectGame.GameField[x, y] == 0)
                    {
                        continue;
                    }
                    DrawChipOnBoard(x, y, connectGame.GameField[x, y] == 1);
                    //DrawChipOnBoard(x, y, x % 2 == 0);
                }
            }

            //Game state
            switch (connectGame.GameState)
            {
            case Span4Game.GameStateType.Draw:
                graphics.DrawText(2, 0, "Draw", Color.White);
                break;

            case Span4Game.GameStateType.Player1Wins:
                graphics.DrawText(2, 0, "Player 1 Wins!", Color.White);
                break;

            case Span4Game.GameStateType.Player2Wins:
                graphics.DrawText(2, 0, "Player 2 Wins!", Color.White);
                break;

            case Span4Game.GameStateType.Player1Turn:
                DrawPreviewChip(currentColumn, true);
                break;

            case Span4Game.GameStateType.Player2Turn:
                DrawPreviewChip(currentColumn, false);
                break;
            }

            //Draw side display

            /*   int xText = 150;
             * graphics.DrawText(xText, 0, "Span4!");
             *
             * graphics.DrawText(xText, 18, "Player 1");
             * DrawChip(xText + 40, 21, 3, true);
             *
             * graphics.DrawText(xText, 27, "Player 2");
             * DrawChip(xText + 40, 30, 3, false);
             *
             * graphics.DrawText(xText, 45, "Score:");
             * graphics.DrawText(xText, 54, $"{connectGame.Player1Wins} to {connectGame.Player2Wins}");  */
        }
Beispiel #16
0
        void DrawGame()
        {
            //draw gameboard
            graphics.DrawRectangle(0, 9, 64, 55, true, false);

            for (int i = 1; i < 7; i++)
            {
                graphics.DrawLine(CellSize * i,
                                  yStart,
                                  CellSize * i,
                                  yStart + CellSize * 6 + 1,
                                  true);
            }

            for (int j = 1; j < 6; j++)
            {
                graphics.DrawLine(xStart,
                                  yStart + j * CellSize,
                                  63 + xStart,
                                  yStart + j * CellSize,
                                  true);
            }

            for (int x = 0; x < connectGame.Width; x++)
            {
                for (int y = 0; y < connectGame.Height; y++)
                {
                    if (connectGame.GameField[x, y] == 0)
                    {
                        continue;
                    }
                    DrawChipOnBoard(x, y, connectGame.GameField[x, y] == 1);
                }
            }

            //Game state
            switch (connectGame.GameState)
            {
            case Span4Game.GameStateType.Draw:
                graphics.DrawText(2, 0, "Draw");
                break;

            case Span4Game.GameStateType.Player1Wins:
                graphics.DrawText(2, 0, "Player 1 Wins!");
                break;

            case Span4Game.GameStateType.Player2Wins:
                graphics.DrawText(2, 0, "Player 2 Wins!");
                break;

            case Span4Game.GameStateType.Player1Turn:
                DrawPreviewChip(currentColumn, true);
                break;

            case Span4Game.GameStateType.Player2Turn:
                DrawPreviewChip(currentColumn, false);
                break;
            }

            //Draw side display
            int xText = 75;

            graphics.DrawText(xText, 0, "Span4!");

            graphics.DrawText(xText, 18, "Player 1");
            DrawChip(115, 21, true);

            graphics.DrawText(xText, 27, "Player 2");
            DrawChip(115, 30, false);

            graphics.DrawText(xText, 45, "Score:");
            graphics.DrawText(xText, 54, $"{connectGame.Player1Wins} to {connectGame.Player2Wins}");
        }