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(); }
private static int screenWidth = 800; // Width of Canvas screen #endregion Fields #region Methods public static void Main(string[] args) { CDrawer canvas = new CDrawer(screenWidth, screenHeight); // Initializes new Canvas window Random rng = new Random(); // Random number generator Ball example = new Ball(screenWidth, screenHeight, 25, 150, 100, 10, 1, 350); Ball example2 = new Ball(screenWidth, screenHeight, 25, 300, 300, 1, 1, 300); for (int i = 0; i < 10000; i++) { canvas.AddEllipse(example.centerX - example.radius, example.centerY - example.radius, 2 * example.radius, 2 * example.radius); canvas.AddEllipse(example2.centerX - example2.radius, example2.centerY - example2.radius, 2 * example2.radius, 2 * example2.radius); System.Threading.Thread.Sleep(5); canvas.Clear(); example.Update(); example.CollideWithWall(); example2.CollideWithWall(); example.CollideWithBall(example2); } Console.ReadKey(); }
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(); */ }
//*************************************************************************************************** //Method: static public void drawMoney(CDrawer window, decimal cashVal, decimal[,] currVals) //Purpose: Displays visually the amounts of denominations to the user in GDI Drawer. //Parameters: CDrawer window - the GDI Drawer window to be drawn to. // decimal cashVal - the total amount of cash being divided. // decimal[,] currVals - the array of denominations being divided into. //Returns: void //**************************************************************************************************** static public void drawMoney(CDrawer window, decimal cashVal, decimal[,] currVals) { //declare vars Color[] colours = { Color.Firebrick, Color.LightGreen, Color.Magenta, Color.LightSkyBlue, Color.Silver, Color.Gold, Color.Silver, Color.Silver, Color.Silver, Color.Brown }; // array of colours to draw the appropriate denomination. //draws total amount at the top. window.AddText(cashVal.ToString("C"), 24, 400, 50, 0, 0, Color.Yellow); //loops to draw each denomination. for (int i = 0, x = 100, y = 100; i < currVals.GetLength(1); ++i) { //checks to make sure drawing won't go off screen. If it might, resets it to the top and //offsets to the right. if (y > 500 && x != 500) { y = 100; x = 500; } //checks to make sure current denomination type is being used. if (currVals[1, i] > 0) { //draws large bills. if (i <= 3) { window.AddRectangle(x, y, 180, 80, colours[i], 1, Color.Beige); window.AddText((currVals[0,i].ToString("C")) + " x " + currVals[1, i].ToString(), 14, x + 90, y + 40, 0, 0, Color.Black); y += 90; } //draws coins. else { window.AddEllipse(x + 45, y, 85, 85, colours[i], 1, Color.Beige); if (currVals[0, i] == 2) window.AddEllipse(x + 63, y + 20, 47, 47, Color.Gold); window.AddText((currVals[0, i].ToString("C")) + " x " + currVals[1, i].ToString(), 14, x + 85, y + 42, 0, 0, Color.Black); y += 90; } } } }
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 MouseMove(Point pos, CDrawer dr) { dr.AddEllipse(pos.X, pos.Y, 5, 5, Color.Red); }
static void LeftClick(Point pos, CDrawer dr) { dr.AddEllipse(pos.X, pos.Y, 10, 10, Color.Yellow); }