static void Background() { Console.WriteLine("Resource Picture"); Bitmap bm = new Bitmap(Properties.Resources.jupiter); CDrawer dr = new CDrawer(bm.Width, bm.Height); dr.ContinuousUpdate = false; dr.SetBBPixel(bm.Width / 2, bm.Height / 2, Color.Wheat); for (int y = 0; y < bm.Height; ++y) for (int x = 0; x < bm.Width; ++x) dr.SetBBPixel(x, y, bm.GetPixel(x, y)); dr.Render(); System.Threading.Thread.Sleep(1000); dr.Close(); }
static void Grid(CDrawer canvas) { for (int x = 0; x < 800; x++) { canvas.SetBBPixel(x, 300, Color.Red); //drawing the x ticks if ((x % unitValue) == 0) { for (int y = 294; y < 306; ++y) canvas.SetBBPixel(x, y, Color.Red); } if ((x % unitValue2) == 0) { for (int y = 297; y < 304; ++y) canvas.SetBBPixel(x, y, Color.Red); } if ((x % unitValue4) == 0) { for (int y = 299; y < 302; ++y) canvas.SetBBPixel(x, y, Color.Red); } } for (int y = 0; y < 600; y++) { canvas.SetBBPixel(400, y, Color.Red); //drawing y ticks if ((y % unitValue3) == 0) { for (int x = 395; x < 405; ++x) canvas.SetBBPixel(x, y, Color.Red); } } }
// DrawGround(screen, y, y_max, color, color) - Colors pixels up to height y from bottom with given colors. private static void DrawGround(CDrawer screen, int groundHeight, int maxHeight, Color primary, Color secondary) { // Bulletproofing arguments if (!(groundHeight > 0 && groundHeight <= maxHeight)) return; // Iterating over area of ground, colouring in stripes of primary and secondary for (int j = screen.m_ciHeight - 1; j > screen.m_ciHeight - groundHeight; j--) { for (int i = 0; i < screen.m_ciWidth; i++) { screen.SetBBPixel(i, j, j % 2 == 0 ? primary : secondary); } } }
// END OF DRAW END OF DRAW END OF DRAW static void PlayBack(int[] arrayOfMoves, int xCoordinate, int yCoordinate, CDrawer s_Draw) { Color r = Color.Red; Color g = Color.Green; Color b = Color.Blue; s_Draw.SetBBPixel(xCoordinate, yCoordinate, b); foreach (int i in arrayOfMoves) { if (arrayOfMoves[i] == 1) { yCoordinate += 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, r); } if (arrayOfMoves[i] == 2) { yCoordinate -= 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, r); } if (arrayOfMoves[i] == 3) { xCoordinate -= 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, r); } if (arrayOfMoves[i] == 4) { xCoordinate += 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, r); } if (arrayOfMoves[i] == 5) { yCoordinate += 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, g); } if (arrayOfMoves[i] == 6) { yCoordinate -= 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, g); } if (arrayOfMoves[i] == 7) { xCoordinate -= 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, g); } if (arrayOfMoves[i] == 8) { xCoordinate += 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, g); } if (arrayOfMoves[i] == 9) { yCoordinate += 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, b); } if (arrayOfMoves[i] == 10) { yCoordinate -= 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, b); } if (arrayOfMoves[i] == 11) { xCoordinate -= 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, b); } if (arrayOfMoves[i] == 12) { xCoordinate += 1; s_Draw.SetBBPixel(xCoordinate, yCoordinate, b); } //end of array draw foreach____ } }
// END OF MAIN END OF MAIN END OF MAIN static int[] Draw(int xCoordinate, int yCoordinate, CDrawer s_Draw) { int[] arrayOfXValues = new int[500000]; int[] arrayOfYValues = new int[500000]; int v = 0; int[] colorAtMove_PlaceDesignator = new int[500000]; int xPoint = xCoordinate; int ypoint = yCoordinate; Color color = Color.Green; Color r = Color.Red; Color g = Color.Green; Color b = Color.Blue; bool success = false; ConsoleKeyInfo lineDirection; do { if (color == Color.Red) { lineDirection = Console.ReadKey(); if (lineDirection.Key == ConsoleKey.UpArrow) { yCoordinate += 1; s_Draw.SetBBPixel(xPoint, ypoint, r); colorAtMove_PlaceDesignator[v] = 1; v += 1; } if (lineDirection.Key == ConsoleKey.DownArrow) { yCoordinate -= 1; s_Draw.SetBBPixel(xPoint, ypoint, r); colorAtMove_PlaceDesignator[v] = 2; v += 1; } if (lineDirection.Key == ConsoleKey.LeftArrow) { xCoordinate -= 1; s_Draw.SetBBPixel(xPoint, ypoint, r); colorAtMove_PlaceDesignator[v] = 3; v += 1; } if (lineDirection.Key == ConsoleKey.RightArrow) { xCoordinate += 1; s_Draw.SetBBPixel(xPoint, ypoint, r); colorAtMove_PlaceDesignator[v] = 4; v += 1; } } if (color == Color.Green) { lineDirection = Console.ReadKey(); if (lineDirection.Key == ConsoleKey.UpArrow) { yCoordinate += 1; s_Draw.SetBBPixel(xPoint, ypoint, g); colorAtMove_PlaceDesignator[v] = 5; v += 1; } if (lineDirection.Key == ConsoleKey.DownArrow) { yCoordinate -= 1; s_Draw.SetBBPixel(xPoint, ypoint, g); colorAtMove_PlaceDesignator[v] = 6; v += 1; } if (lineDirection.Key == ConsoleKey.LeftArrow) { xCoordinate -= 1; s_Draw.SetBBPixel(xPoint, ypoint, g); colorAtMove_PlaceDesignator[v] = 7; v += 1; } if (lineDirection.Key == ConsoleKey.RightArrow) { xCoordinate += 1; s_Draw.SetBBPixel(xPoint, ypoint, g); colorAtMove_PlaceDesignator[v] = 8; v += 1; } } if (color == Color.Blue) { lineDirection = Console.ReadKey(); if (lineDirection.Key == ConsoleKey.UpArrow) { yCoordinate += 1; s_Draw.SetBBPixel(xPoint, ypoint, b); colorAtMove_PlaceDesignator[v] = 9; v += 1; } if (lineDirection.Key == ConsoleKey.DownArrow) { yCoordinate -= 1; s_Draw.SetBBPixel(xPoint, ypoint, b); colorAtMove_PlaceDesignator[v] = 10; v += 1; } if (lineDirection.Key == ConsoleKey.LeftArrow) { xCoordinate -= 1; s_Draw.SetBBPixel(xPoint, ypoint, b); colorAtMove_PlaceDesignator[v] = 11; v += 1; } if (lineDirection.Key == ConsoleKey.RightArrow) { xCoordinate += 1; s_Draw.SetBBPixel(xPoint, ypoint, b); colorAtMove_PlaceDesignator[v] = 12; v += 1; } } } while (!success); return arrayOfXValues; }
//************************************************************************************************************** // Methods for Graphics (Using GDIDrawer -- CDrawer) // DrawTrajectory(screen, x, y, color) - Draws trajectory of shot based on height of shot as a function of distance // Note that this would need to be generalized to incorporate wind resistance, // as it is it will only draw parabolic trajectory paths from left to right. // DrawTarget(screen, x, y, color) - Draws sprite with top left position (x,y) on screen with specified color. // DrawCannon(screen, x, y, angle(degrees), color, color) - Draws sprite with top left position (x,y) on screen // with specified colors and changes given the angle. // DrawGround(screen, y, y_max, color, color) - Colors pixels up to height y from bottom with given colors. // RefreshSprites(...) - Clears screen, calls DrawTarget and DrawCannon and renders screen. // RefreshScreen(...) - Clears screen, calls DrawGround and RefreshSprites. //************************************************************************************************************** // DrawTrajectory(screen, groundy, x, y, v, angle, color, gravity, scale) - Draws trajectory of shot based on height // of shot as a function of distance Note that this would need to be generalized to incorporate wind resistance, as // it is it will only draw parabolic trajectory paths from left to right. private static void DrawTrajectory(CDrawer screen, int groundHeight, int initialX, int initialY, double initialVelocity, byte shotAngle, Color pathColor, double gravity = 9.81D, int scale = 1) { int baseHeight = screen.m_ciHeight - groundHeight; // Ground level on screen int currentX = initialX; // Current X coordinate on screen int currentY = baseHeight - initialY; // Current Y coordinate on screen int distance = 0; // Current distance traveled do { // Set pixel at calculated coordinate to pathColor if on screen if (currentX >= 0 && currentX < screen.m_ciWidth && currentY >= 0 && currentY < screen.m_ciHeight) screen.SetBBPixel(currentX, currentY, pathColor); // Update currentX += 1; distance += scale; currentY = baseHeight - HeightOfProjectile(initialY, initialVelocity, distance, shotAngle, gravity); } while (currentY < screen.m_ciHeight - groundHeight); // Once shot hits ground, stop drawing and add ball screen.AddCenteredEllipse(currentX, currentY, 10, 10, Color.White); screen.Render(); }
// RefreshScreen(...) - Clears screen, calls DrawGround and RefreshSprites. private static void RefreshScreen(CDrawer screen, int groundHeight, Color groundPrimary, Color groundSecondary, int cannonX, int cannonY, int targetX, int targetY, Color wheel, Color barrel, int barrelAngle, Color target) { // Wipe entire screen -- better way to do this is LockBits? for (int i = 0; i < screen.m_ciWidth; i++) for (int j = 0; j < screen.m_ciHeight; j++) screen.SetBBPixel(i, j, Color.Black); // Redraw screen with updated information DrawGround(screen, groundHeight, 50, groundPrimary, groundSecondary); RefreshSprites(screen, cannonX, targetX, cannonY, targetY, barrelAngle, wheel, barrel, target); }
private void SetGuard(CDrawer dr, int ix, int iy, Color col) { if (ix >= 0 && ix < dr.m_ciWidth && iy >= 0 && iy < dr.m_ciHeight) dr.SetBBPixel(ix, iy, col); }
static void RandomBlocks() { Random rnd = new Random(); CDrawer can = new CDrawer(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Reset(); watch.Start(); can.AddText("Random Known Colors SetBBPixel : 2s", 28, 0, 0, can.ScaledWidth, can.ScaledHeight, Color.White); can.AddText("Random Known Colors SetBBPixel : 2s", 28, 2, 2, can.ScaledWidth + 2, can.ScaledHeight + 2, Color.Black); while (watch.ElapsedMilliseconds < 2000) { can.SetBBPixel(rnd.Next(can.ScaledWidth), rnd.Next(can.ScaledHeight), RandColor.GetKnownColor()); } can.Close(); can = new CDrawer(800, 800); can.Scale = 10; Console.WriteLine("Random Known Colors SetBBScaledPixel : 2s"); watch.Reset(); watch.Start(); can.AddText("Random Known Colors SetBBScaledPixel : 2s", 24); while (watch.ElapsedMilliseconds < 2000) { can.SetBBScaledPixel(rnd.Next(can.ScaledWidth), rnd.Next(can.ScaledHeight), RandColor.GetKnownColor()); } can.Close(); }