void DrawTetrisField()
        {
            graphics.DrawText(0, 0, $"{game.LinesCleared}");

            int yOffset = 8;

            //draw current piece
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (game.IsPieceLocationSet(i, j))
                    {
                        graphics.DrawPixel((game.CurrentPiece.X + i),
                                           game.CurrentPiece.Y + j + yOffset);
                    }
                }
            }

            //draw gamefield
            for (int i = 0; i < game.Width; i++)
            {
                for (int j = 0; j < game.Height; j++)
                {
                    if (game.IsGameFieldSet(i, j))
                    {
                        graphics.DrawPixel(i, j + yOffset);
                    }
                }
            }
        }
        void DisplayJPG()
        {
            var jpgData = LoadResource(images[selectedIndex]);
            var decoder = new JpegDecoder();
            var jpg     = decoder.DecodeJpeg(jpgData);

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

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

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

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

            graphics.Show();
        }
        void DisplayJPG(int weatherCode, int xOffset, int yOffset)
        {
            var jpgData = LoadResource(weatherCode);
            var decoder = new JpegDecoder();
            var jpg     = decoder.DecodeJpeg(jpgData);

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

            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;
                }
            }
        }
Esempio n. 4
0
        void DisplayJPG(int x, int y)
        {
            var jpgData = LoadResource("meadow.jpg");
            var decoder = new JpegDecoder();
            var jpg     = decoder.DecodeJpeg(jpgData);

            int  imageX = 0;
            int  imageY = 0;
            byte r, g, b;

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

                graphics.DrawPixel(imageX + x, imageY + y, Color.FromRgb(r, g, b));

                imageX++;
                if (imageX % decoder.Width == 0)
                {
                    imageY++;
                    imageX = 0;
                }
            }

            graphics.Show();
        }
Esempio n. 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 RotaryXRotated(object sender, RotaryChangeResult e)
        {
            if (e.New == RotationDirection.Clockwise)
            {
                x++;
            }
            else
            {
                x--;
            }

            if (x > 239)
            {
                x = 239;
            }
            else if (x < 0)
            {
                x = 0;
            }

            graphics.DrawPixel(x, y + 1, Color.Red);
            graphics.DrawPixel(x, y, Color.Red);
            graphics.DrawPixel(x, y - 1, Color.Red);
            graphics.Show();
        }
        void DrawBitmap(int x, int y, int width, int height, byte[] bitmap)
        {
            for (var ordinate = 0; ordinate < height; ordinate++)    //y
            {
                for (var abscissa = 0; abscissa < width; abscissa++) //x
                {
                    var  b    = bitmap[(ordinate * width) + abscissa];
                    byte mask = 0x01;

                    for (var pixel = 0; pixel < 8; pixel++)
                    {
                        if ((b & mask) > 0)
                        {
                            graphics.DrawPixel(x + (8 * abscissa) + 7 - pixel, y + ordinate);
                        }
                        else
                        {
                            graphics.DrawPixel(x + (8 * abscissa) + 7 - pixel, y + ordinate, false);
                        }
                        mask <<= 1;
                    }
                }
            }
        }
        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);
        }