// 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. private static void DrawCannon(CDrawer screen, int topLeftX, int topLeftY, int barrelAngle, Color wheel, Color barrel) { // Bulletproofing wheel center to be inside screen if (!(topLeftX + 10 >= 0 && topLeftX + 10 < screen.m_ciWidth) || !(topLeftY + 10 >= 0 && topLeftY - 10 < screen.m_ciHeight)) return; // Drawing wheel, clearing inside of wheel, and drawing cannon barrel // Note that the barrelAngle is relative to straight up = 0 degrees; positive x axis = 90 degrees; screen.AddCenteredEllipse(topLeftX + 10, topLeftY + 10, 20, 20, wheel); screen.AddCenteredEllipse(topLeftX + 10, topLeftY + 10, 18, 18, Color.Black); screen.AddLine(topLeftX + 10, topLeftY + 10, 20, barrelAngle * Math.PI / 180, barrel, 10); }
// DrawTarget(screen, x, y, color) - Draws sprite with top left position (x,y) on screen with specified color. private static void DrawTarget(CDrawer screen, int topLeftX, int topLeftY, Color target) { // Bulletproofing target center inside screen if (!(topLeftX + 10 >= 0 && topLeftX + 10 < screen.m_ciWidth) || !(topLeftY + 10 >= 0 && topLeftY - 10 < screen.m_ciHeight)) return; // Drawing target screen.AddCenteredEllipse(topLeftX + 10, topLeftY + 10, 20, 20, target); }
public void ShowBall(CDrawer Canvas) { Canvas.AddCenteredEllipse(_LocationCenter.X,_LocationCenter.Y, _BallRadius,_BallRadius,Color.FromArgb(_BallOpacity, _BallColor.R,_BallColor.G,_BallColor.B)); }
public void ShowBall(CDrawer GDI_canvas) { GDI_canvas.AddCenteredEllipse(_point.X, _point.Y, _ballRadius*2, _ballRadius*2, Color.FromArgb(BallOpacity, _ballColor)); }
public void Show(CDrawer canvas, int ballCount) { Color complimentColor = Color.FromArgb(BallColor.ToArgb() ^ 0x00FFFFFF); canvas.AddCenteredEllipse(_ballLocation.X, _ballLocation.Y, _ballRadius * 2, _ballRadius * 2, BallColor); canvas.AddText(ballCount.ToString(), 14, _ballLocation.X - _ballRadius, _ballLocation.Y - _ballRadius, _ballRadius*2, _ballRadius*2, complimentColor); }
public void Show(CDrawer Canvas, int num) { Canvas.AddCenteredEllipse(newPoint.X, newPoint.Y, ballRadius * 2, ballRadius * 2, ballColor); Canvas.AddText(num.ToString(), 14, newPoint.X - ballRadius, newPoint.Y - ballRadius, ballRadius * 2, ballRadius * 2, Color.FromArgb(ballColor.ToArgb() ^ 0x00FFFFFF)); Canvas.Render(); }
//************************************************************************************************************** // 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(); }
protected override void vRender(CDrawer dr) { dr.AddCenteredEllipse(position.X, position.Y, temp_size, temp_size, Color.White); }
protected override void vRender(CDrawer dr) { dr.AddCenteredEllipse(position.X, position.Y, size, size, color); }
public override void Draw(CDrawer canv) { canv.AddCenteredEllipse(_liCenter.X, _liCenter.Y, 60, 60, Color.FromArgb(_alpha, _liColor)); base.Draw(canv); }
public virtual void Draw(CDrawer canv) { canv.AddCenteredEllipse(_liCenter.X, _liCenter.Y, 8, 8, Color.Red); }
static void Main(string[] args) { Random randomNumber = new Random(); bool success = false; Console.Write("Press the spacebar to evaluate a pair of circles."); do { ConsoleKeyInfo entry = Console.ReadKey(); if (entry.Key == ConsoleKey.Spacebar) { success = true; } if (success) { int x1 = randomNumber.Next(200, 600); int y1 = randomNumber.Next(200, 400); int x2 = randomNumber.Next(200, 600); int y2 = randomNumber.Next(200, 400); int radius1 = randomNumber.Next(25, 201); int radius2 = randomNumber.Next(25, 201); //imagining a triangle with: a == (distance between x1 and x2); b == (distance between y1 and y2); and c == (distance between centers of the circles). int a = x2 - x1; int b = y2 - y1; double c = Math.Sqrt(Math.Pow(a, 2) + Math.Pow(b, 2)); if ((radius1 + radius2)/2 >= c) { CDrawer canvas = new CDrawer(800, 600); canvas.AddCenteredEllipse(x1, y1, radius1, radius1, Color.Red); canvas.AddCenteredEllipse(x2, y2, radius2, radius2, Color.Red); } if (radius1 + radius2 < c) { CDrawer canvas2 = new CDrawer(800, 600); canvas2.AddCenteredEllipse(x1, y1, radius1, radius1, Color.Blue); canvas2.AddCenteredEllipse(x2, y2, radius2, radius2, Color.YellowGreen); } Console.Write(""); } ConsoleKeyInfo entryb = Console.ReadKey(); if (entryb.Key == ConsoleKey.Spacebar) { success = false; } else { success = true; } } while (!success); Console.ReadKey(); }
static void ClickEllipses() { Random rnd = new Random(); CDrawer can = new CDrawer(); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Reset(); watch.Start(); can.AddText("Random Bounding Box Ellipses : 2s", 28, 0, 0, can.ScaledWidth, can.ScaledHeight, Color.White); can.AddText("Random Bounding Box Ellipses : 2s", 28, 2, 2, can.ScaledWidth + 2, can.ScaledHeight + 2, Color.Black); while (watch.ElapsedMilliseconds < 5000) { Point p = new Point(rnd.Next(-50, can.ScaledWidth + 50), rnd.Next(-50, can.ScaledHeight - 50)); switch (rnd.Next(6)) { case 0: can.AddEllipse(p.X, p.Y, 100, 100); break; case 1: can.AddEllipse(p.X, p.Y, 100, 100, RandColor.GetKnownColor(), rnd.Next(1, 4), RandColor.GetKnownColor()); break; case 2: can.AddPolygon(p.X, p.Y, 100, rnd.Next(3, 8)); break; case 3: can.AddPolygon(p.X, p.Y, 100, rnd.Next(3, 8), rnd.NextDouble() * Math.PI, RandColor.GetKnownColor(), 2, RandColor.GetKnownColor()); break; case 4: can.AddRectangle(p.X, p.Y, 100, 100); break; case 5: can.AddRectangle(p.X, p.Y, 100, 100, RandColor.GetKnownColor(), rnd.Next(1, 4), RandColor.GetKnownColor()); break; default: break; } System.Threading.Thread.Sleep(100); } can.Close(); can = new CDrawer(1000, 400, false); //System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Reset(); watch.Start(); can.AddText("Random Bounding Box Ellipses : 2s", 28, 0, 0, can.ScaledWidth, can.ScaledHeight, Color.White); can.AddText("Random Bounding Box Ellipses : 2s", 28, 2, 2, can.ScaledWidth + 2, can.ScaledHeight + 2, Color.Black); while (watch.ElapsedMilliseconds < 2000) { Point p = new Point(rnd.Next(50, can.ScaledWidth - 50), rnd.Next(50, can.ScaledHeight - 50)); can.AddCenteredEllipse(p.X, p.Y, 100, 100, RandColor.GetKnownColor(), 2, Color.White); can.AddCenteredEllipse(p.X, p.Y, 5, 5, RandColor.GetKnownColor(), 1, Color.Red); System.Threading.Thread.Sleep(100); } can.Render(); System.Threading.Thread.Sleep(1000); can.Close(); }
static void SBlocks() { CDrawer can = new CDrawer(800, 600, false); for (int i = 0; i < 500; ++i) { can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1, RandColor.GetColor()); can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1); can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor()); can.AddCenteredEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800)); can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1, RandColor.GetColor()); can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor(), 1); can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), RandColor.GetColor()); can.AddEllipse(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 800)); try { can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor(), 1, RandColor.GetColor()); can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor(), 1); can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2, RandColor.GetColor()); can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64), s_rnd.NextDouble() * Math.PI * 2); can.AddPolygon(s_rnd.Next(0, 800), s_rnd.Next(0, 800), s_rnd.Next(0, 300), s_rnd.Next(0, 64)); } catch (Exception err) { Console.WriteLine(err.Message); } try { can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor(), 1, RandColor.GetColor()); can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor(), 1); can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), RandColor.GetColor()); can.AddRectangle(s_rnd.Next(-10, 810), s_rnd.Next(-10, 610), s_rnd.Next(-10, 810), s_rnd.Next(-10, 610)); } catch (Exception err) { Console.WriteLine(err.Message); } try { can.AddText("Rats", s_rnd.Next(0, 100), s_rnd.Next (0, 800), s_rnd.Next (0, 600), s_rnd.Next(0, 200), s_rnd.Next (0, 200), RandColor.GetColor()); can.AddText("Rats", s_rnd.Next(0, 100), s_rnd.Next(0, 800), s_rnd.Next(0, 600), s_rnd.Next(0, 200), s_rnd.Next(0, 200)); can.AddText("Rats", s_rnd.Next(0, 100), RandColor.GetColor()); } catch (Exception err) { Console.WriteLine(err.Message); } } can.Render(); Console.ReadKey(); }