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); } } } }
static void StartGameLoop() { while (true) { graphics.Clear(); game.Update(); //draw food graphics.DrawPixel(game.FoodPosition.X, game.FoodPosition.Y); //draw food for (int i = 0; i < game.SnakePosition.Count; i++) { var point = (Point)game.SnakePosition[i]; graphics.DrawPixel(point.X, point.Y); } if (game.PlaySound) { speaker.PlayTone(440, 25); } //show graphics.Show(); Thread.Sleep(250 - game.Level * 5); } }
void Loop() { int count = 0; int x = 0, y = 0; int xD = 1, yD = 1; while (count < 150 && playGame == true) { graphics.Clear(); graphics.DrawText(0, 0, $"{command}:"); graphics.DrawText(0, 20, $"{count++}"); graphics.DrawPixel(x += xD, y += yD); if (x == graphics.Width || x == 0) { xD *= -1; } ; if (y == graphics.Height || y == 0) { yD *= -1; } ; graphics.Show(); } }
void RunEmulator() { Console.WriteLine("Starting emulator"); while (true) { try { speccy.DoIntructions(69888 * 50); Console.WriteLine("OnCycle"); var screen = speccy.GetScreenInUint(true); Console.WriteLine("Got screen"); //graphics.Clear(); for (int y = 0; y < 128; y++) { for (int x = 0; x < 128; x++) { graphics.DrawPixel(x, y, Color.FromUint(screen[(y * 256 * 2) + x * 2])); } } graphics.Show(); Console.WriteLine("Showing screen"); } catch (Exception ex) { Console.WriteLine(ex.Message); } } }
protected void DisplayJPG() { var jpgData = LoadResource("meadow.jpg"); 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 + 55, y + 40, Color.FromRgb(r, g, b)); x++; if (x % decoder.Width == 0) { y++; x = 0; } } display.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; } } }
public MeadowApp() { x = y = 120; var config = new SpiClockConfiguration( speedKHz: 6000, mode: SpiClockConfiguration.Mode.Mode3); st7789 = new St7789( device: Device, spiBus: Device.CreateSpiBus( clock: Device.Pins.SCK, mosi: Device.Pins.MOSI, miso: Device.Pins.MISO, config: config), chipSelectPin: null, dcPin: Device.Pins.D01, resetPin: Device.Pins.D00, width: 240, height: 240); graphics = new GraphicsLibrary(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; }
async Task StartGame(string command) { Console.WriteLine($"******** {command}"); playGame = true; int count = 0; int x = 0, y = 0; int xD = 1, yD = 1; await Task.Run(() => { while (count < 150 && playGame == true) { graphics.Clear(); graphics.DrawText(0, 0, $"{command}:"); graphics.DrawText(0, 20, $"{count++}"); graphics.DrawPixel(x += xD, y += yD); if (x == graphics.Width || x == 0) { xD *= -1; } ; if (y == graphics.Height || y == 0) { yD *= -1; } ; graphics.Show(); } }).ConfigureAwait(false); EnableMenu(); }
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 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; } } display.Show(); }
void RotaryXRotated(object sender, RotaryTurnedEventArgs e) { if (e.Direction == 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 Face() { Console.WriteLine("Face..."); charlieWing.Clear(); charlieWing.Frame = 0; graphics.DrawCircle(6, 3, 3); graphics.DrawPixel(5, 2); graphics.DrawPixel(7, 2); graphics.DrawLine(5, 4, 7, 4, true); charlieWing.Show(0); charlieWing.Frame = 1; graphics.DrawCircle(6, 3, 3); graphics.DrawPixel(5, 2); graphics.DrawPixel(7, 2); graphics.DrawPixel(5, 4); graphics.DrawPixel(6, 5); graphics.DrawPixel(7, 4); byte frameIndex = 0; for (int i = 0; i < 10; i++) { charlieWing.Show(frameIndex); frameIndex = (frameIndex == 0) ? (byte)1 : (byte)0; Thread.Sleep(1000); } }
/// <summary> /// Use the meadow graphics library to draw the expressive pixels - I Frame /// </summary> private void Display(IFrameDef ifd, ushort xPos, ushort yPos, ushort zoom) { int x = xPos; int y = yPos; foreach (var p in ifd.PalIndex) { if (zoom == 1) { graphics.DrawPixel(x, y, Pallette[p]); x += 1; if (x - xPos >= Width) { x = xPos; y += 1; } } else if (zoom == 2 || zoom == 3) { graphics.Stroke = zoom; graphics.DrawLine(x, y, x + zoom - 1, y, Pallette[p]); x += zoom; if (x - xPos >= Width * zoom) { x = xPos; y += zoom; } } else { graphics.DrawRectangle(x, y, zoom, zoom, Pallette[p], true); x += zoom; if (x - xPos >= Width * zoom) { x = xPos; y += zoom; } } } }
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; } } } }
int BenchPix(int num) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); graphics.Stroke = 1; graphics.Clear(true); for (int i = 1; i < num; i++) { graphics.DrawPixel(rand.Next(displayWidth), rand.Next(displayHeight), RandColor()); graphics.Show(); } int p1 = (int)stopWatch.Elapsed.TotalMilliseconds; Console.WriteLine($"{num} Pixel {p1}ms"); stopWatch.Stop(); return(p1); }
void ShowJpeg() { var jpgData = this.LoadResource(images[this.selectedIndex]); var decoder = new JpegDecoder(); var jpg = decoder.DecodeJpeg(jpgData); Console.WriteLine($"Jpeg decoded is {jpg.Length} bytes"); Console.WriteLine($"Width {decoder.Width}"); Console.WriteLine($"Height {decoder.Height}"); this.graphics.Clear(); this.display.Show(); 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; } } this.display.Show(); }
void DrawVertices() { graphics.DrawPixel((int)rotationXXX, (int)rotationYYY); }