public Form1() { InitializeComponent(); pDrawer = new PicDrawer(Properties.Resources.ImageInImageMedium); pDrawer.Render(); liLight = new List<Light>(); timer1.Enabled = true; }
static void CenteredRectangleTest() { CDrawer can = new CDrawer(800, 600, false); can.AddCenteredRectangle(400, 300, 796, 596, Color.Red); for (int i = 0; i < 500; ++i) can.AddCenteredRectangle(s_rnd.Next(100, 700), s_rnd.Next(100, 500), s_rnd.Next(5, 190), s_rnd.Next(5, 190), RandColor.GetColor(), s_rnd.Next(6), RandColor.GetColor()); can.Render(); Console.ReadKey(); }
static void Bezier() { CDrawer can = new CDrawer(800, 600, false); for (int ix = 0; ix < 800; ix += 50) { can.AddBezier(0, 600, ix, 0, 800 - ix, 600, 800, 0, Color.Red, 2); can.AddBezier(0, 0, ix, 0, 800 - ix, 600, 800, 600, Color.Red, 2); } can.Render(); Console.ReadKey(); }
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(); }
//helper methods private static void RenderGrid(CDrawer canvas, Color[,] colAr) { canvas.Clear(); for (int iR = 0; iR < canvas.ScaledHeight; iR++) for (int iC = 0; iC < canvas.ScaledWidth; iC++) canvas.SetBBScaledPixel(iC, iR, colAr[iR, iC]); for (int i = 0; i < canvas.ScaledWidth; i++) canvas.AddLine(i, 0, i, canvas.ScaledWidth, Color.Black, 1); for (int i = 0; i < canvas.ScaledHeight; i++) canvas.AddLine(0, i, canvas.ScaledWidth, i, Color.Black, 1); canvas.Render(); }
static void Main(string[] args) { CDrawer dr = new CDrawer(); dr.BBColour = Color.White; Random rnd = new Random(); dr.Scale = 20; // adjust scale to test ScaledWidth/ScaledHeight // Disable continuous update dr.ContinuousUpdate = false; // perform lengthy/high object count operation for (int i = 0; i < 1000; ++i) { dr.AddEllipse(rnd.Next(dr.ScaledWidth), rnd.Next(dr.ScaledHeight), 1, 1, RandColor.GetColor()); dr.Render(); // tell drawer to show now, all elements have been added } int iNum = 0; iNum++; Point pCoord; // coords to accept mouse click pos int iNumClicks = 0; // count number of clicks accepted int iFalseAlarm = 0; // count the number of poll calls do { bool bRes = dr.GetLastMouseLeftClick(out pCoord); // poll if (bRes) // new coords? { ++iNumClicks; dr.AddEllipse(pCoord.X - 10, pCoord.Y - 10, 20, 20); } else iFalseAlarm++; // not new coords } while (iNumClicks < 10); Console.WriteLine("Checked for coordinates " + iFalseAlarm.ToString() + " times!"); Console.ReadKey(); /* { FileStream foo = new FileStream("snot", FileMode.Create); MemoryStream ms = new MemoryStream(); BinaryFormatter bf = new BinaryFormatter(); SThing temp = new SThing(); temp.i = 42; bf.Serialize(ms, temp); foo.Write(ms.GetBuffer(), 0, (int)ms.Length); foo.Close(); } { FileStream foo = new FileStream("snot", FileMode.Open); BinaryFormatter bf = new BinaryFormatter(); object o = bf.Deserialize(foo); if (o is SThing) { SThing temp = (SThing)o; Console.WriteLine (temp.i.ToString()); } } Console.ReadKey(); */ }
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(); }
// RefreshSprites(...) - Clears screen, calls DrawTarget and DrawCannon and renders screen. private static void RefreshSprites(CDrawer screen, int cannonX, int targetX, int cannonY, int TargetY, int barrelAngle, Color wheel, Color barrel, Color target) { screen.Clear(); DrawCannon(screen, cannonX, cannonY, MyMethods.ConvertDegreesToGDIDrawerLineRotation(barrelAngle), wheel, barrel); DrawTarget(screen, targetX, TargetY, target); screen.Render(); }
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 SLines() { CDrawer can = new CDrawer(800, 600, false); can.AddLine(10, 10, 790, 590, Color.Red, 2); for (double d = 0; d < Math.PI * 2; d += Math.PI / 32) can.AddLine(new Point (400, 300), 50 * d, d); for (int x = 0; x < 600; x += 5) { can.AddLine(0, 600 - x, x, 0, RandColor.GetColor(), 1); } can.Render(); Console.ReadKey(); }
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(); }
static void Lines() { CDrawer can = new CDrawer(800, 600, false); can.Scale = 10; for (int i = -10; i < can.ScaledWidth + 1; i += 5) { for (int j = -10; j < can.ScaledHeight + 1; j += 5) { can.AddLine(i, j, can.ScaledWidth + 1 - i, can.ScaledHeight + 1 - j, RandColor.GetKnownColor(), 1); } } can.AddText("check...check.. ", 48); can.AddText("one two three", 12, -10, -10, 100, 50, Color.White); can.Render(); Console.ReadKey(); }