private void FormTrekLights_Load(object sender, EventArgs e) { canvas = new CDrawer(800, 600, false, false); trekLightList = new List<TrekLight>(); canvas.Scale = 50; }
static void Main(string[] args) { //declare vars bool runProg = true; // flags to see if program should continue running and restart decimal userMoney; // stores total amount of money user is calcuating CDrawer window = new CDrawer(); // window where money is visually drawn decimal[,] cashAndCoins = null; // array to store cash/coin amounts and discrete amounts of each for // a given cash value //loops if the user wishes to restart and try again. do { //resets all values, if possible if (cashAndCoins != null) Array.Clear(cashAndCoins, 1, 10); window.Clear(); Console.Clear(); Console.WriteLine("\t\tCMPE 1700 Money Calculator\n\n"); // gets input from user, and sends it to be calculated and stored in the array. userMoney = getMoney(); cashAndCoins = calcMoney(userMoney); //displays the amount and draws it in GDIDrawer. Console.WriteLine("Now displaying {0:C}", userMoney); drawMoney(window, userMoney, cashAndCoins); //checks to see if user wants to run again, which they can do by pressing the Enter key. Console.Write("Press Enter to run again, or any other key to exit."); if (!(Console.ReadKey().Key.Equals(ConsoleKey.Enter))) runProg = false; } while (runProg); }
//methods public void MoveBall(CDrawer GDI_canvas) { if (_point.X + _xVelocity >= GDI_canvas.ScaledWidth - _ballRadius) { _point.X = GDI_canvas.ScaledWidth - _ballRadius; _xVelocity *= -1; } if (_point.X + _xVelocity <= _ballRadius) { _point.X = _ballRadius; _xVelocity *= -1; } if (_point.Y + _yVelocity >= GDI_canvas.ScaledHeight - _ballRadius) { _point.Y = GDI_canvas.ScaledHeight - _ballRadius; _yVelocity *= -1; } if (_point.Y + _yVelocity <= _ballRadius) { _point.Y = _ballRadius; _yVelocity *= -1; } _point.X += _xVelocity; _point.Y += _yVelocity; }
public DrawerWnd(CDrawer dr) { InitializeComponent(); // use the log as built from parent _log = dr._log; // save window size m_ciWidth = dr.m_ciWidth; m_ciHeight = dr.m_ciHeight; // cap delegates, this will be set by owner m_delRender = null; m_delMouseMove = null; m_delMouseLeftClick = null; m_delMouseRightClick = null; // cap/set references m_bgc = new BufferedGraphicsContext(); m_bg = null; // create the bitmap for the underlay and clear it to whatever colour m_bmUnderlay = new Bitmap(dr.m_ciWidth, dr.m_ciHeight); // docs say will use Format32bppArgb // fill the bitmap with the default drawer bb colour FillBB(Color.Black); // show that drawer is up and running _log.WriteLine("Drawer Started..."); }
//Event Handler for Keyboard things private void HandleKey(bool bIsDown, Keys keycode, GDIDrawer.CDrawer drawer) { // Don't do anything until they release the key (the event fires multiples). if (bIsDown) { return; } switch (keycode) { case Keys.D: //Delete a ball lock (Balls) if (Balls.Count > 0) { Balls.RemoveAt(0); } break; case Keys.A: //Add a ball lock (Balls) Balls.Add(new Ball(true)); break; } }
//instance methods public void Move(CDrawer canvas) { if (_ballLocation.X + _ballXVelocity >= canvas.ScaledWidth - _ballRadius) { _ballLocation.X = canvas.ScaledWidth - _ballRadius; _ballXVelocity *= -1; } if (_ballLocation.X + _ballXVelocity <= _ballRadius) { _ballLocation.X = _ballRadius; _ballXVelocity *= -1; } if (_ballLocation.Y + _ballYVelocity >= canvas.ScaledHeight - _ballRadius) { _ballLocation.Y = canvas.ScaledHeight - _ballRadius; _ballYVelocity *= -1; } if (_ballLocation.Y + _ballYVelocity <= _ballRadius) { _ballLocation.Y = _ballRadius; _ballYVelocity *= -1; } _ballLocation.X += _ballXVelocity; _ballLocation.Y += _ballYVelocity; }
public void Move(CDrawer Canvas) { newPoint.X += ballXVelocity; newPoint.Y += ballYVelocity; if (newPoint.X - ballRadius < 0) { newPoint.X = ballRadius; ballXVelocity *= -1; } if (newPoint.X + ballRadius > Canvas.ScaledWidth) { newPoint.X = Canvas.ScaledWidth-ballRadius; ballXVelocity *= -1; } if (newPoint.Y - ballRadius < 0) { newPoint.Y = ballRadius; ballYVelocity *= -1; } if (newPoint.Y + ballRadius > Canvas.ScaledHeight) { newPoint.Y = Canvas.ScaledHeight-ballRadius; ballYVelocity *= -1; } }
public Fungus(Point s, CDrawer c, EColor e) { this.canvas = c; this.start = s; this.e = e; this.color_strength = 64; }
//Event Handler for Keyboard things private void HandleKey(bool bIsDown, Keys keycode, GDIDrawer.CDrawer drawer) { // Don't do anything until they release the key (the event fires multiples). if (bIsDown) { return; } switch (keycode) { case Keys.D: //Delete a Shape lock (Shapes) if (Shapes.Count > 0) { Shapes.RemoveAt(0); } break; case Keys.A: //Add a Shape lock (Shapes) Shapes.Add(new Circle()); break; } }
private void Form1_Load(object sender, EventArgs e) { canvas = new CDrawer(800, 600, false, false); timer1.Interval = 20; timer1.Enabled = true; ballsList = new List<Ball>(); }
private void btnStart_Click(object sender, EventArgs e) { if (Canvas == null) Canvas = new CDrawer(); Thread t = new Thread(new ParameterizedThreadStart(BallThread)); t.IsBackground = true; t.Start(tbSize.Value); Threads.Add(t); }
public Rectangle NextDrawerRect(CDrawer canv) { int rWidth = Next(10, MaxSize); int rHeight = Next(10, MaxSize); return new Rectangle(Next(0, canv.ScaledWidth - rWidth), Next(0, canv.ScaledHeight - rHeight), rWidth, rHeight); }
public Form1() { InitializeComponent(); pDrawer = new PicDrawer(Properties.Resources.ImageInImageMedium); pDrawer.Render(); liLight = new List<Light>(); timer1.Enabled = true; }
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 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(); }
// 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); }
//Event Handler for Mouse things private void HandleMouse(System.Drawing.Point pos, GDIDrawer.CDrawer drawer) { //add a ball when and where you click lock (Balls) //The other thread might be using it { Ball b = new Ball(true); b.Location = new PointF(pos.X, pos.Y); Balls.Add(b); } }
//Event Handler for Mouse things private void HandleMouse(System.Drawing.Point pos, GDIDrawer.CDrawer drawer) { //add a Shape when and where you click lock (Shapes) //The other thread might be using it { Shape s = new Ellipse(); s.Location = new PointF(pos.X, pos.Y); Shapes.Add(s); } }
public void Render(CDrawer dr, int CellX, int CellY) { if (CharMap.ContainsKey(Code)) { for (int iy = 0; iy < 7; ++iy) for (int ix = 0; ix < 5; ++ix) if (CharMap[Code][iy, ix]) SetSub(dr, ix, iy, CellX, CellY, ForeCol); else SetSub(dr, ix, iy, CellX, CellY, BackCol); } }
// 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); }
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(); }
//render method public void Render(CDrawer canvas, int lightNum) { int x; int y; x = lightNum % canvas.ScaledWidth; y = lightNum / canvas.ScaledWidth; if ((_byTick >= _byThreshold)&&(y<canvas.ScaledHeight)) { canvas.AddRectangle(x, y, 1, 1, _LightColor, _Border, Color.Black); } }
public void MoveBall(CDrawer Canvas) { int tempX = _LocationCenter.X; int tempY = _LocationCenter.Y; if (tempX < 0 || tempX > Canvas.ScaledWidth) { _xVelocity = _xVelocity * -1; } if (tempY < 0 || tempY > Canvas.ScaledHeight) { _yVelocity = _yVelocity * -1; } _LocationCenter.X = _LocationCenter.X + _xVelocity; _LocationCenter.Y = _LocationCenter.Y + _yVelocity; }
// 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); } } }
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(); }
public Form1() { InitializeComponent(); canvas = new CDrawer(bContinuousUpdate: false); canvas.Scale = 20; liPoint = new List<Point>(); colArray = new Color[canvas.ScaledHeight, canvas.ScaledWidth]; for (int iR = 0; iR < canvas.ScaledHeight; iR++) for (int iC = 0; iC < canvas.ScaledWidth; iC++) colArray[iR, iC] = Color.Salmon; InitThreadsBackground(); }
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); } } }
private void btnSimulate_Click(object sender, EventArgs e) { itemsTotal = 0; sheepStack.Clear(); sheepList.Clear(); if (canvas != null) canvas.Close(); canvas = new CDrawer(900, 400, false, false); canvas.Scale = 20; for (int i = 0; i < 200; i++) sheepStack.Push(new Sheeple()); for (int i = 0; i < numericUpDown1.Value; i++) sheepList.Add(new Queue<Sheeple>()); this.Text = itemsTotal.ToString(); }
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(); }
//IRenderable: Display the shape on the provided canvas public abstract void Render(GDIDrawer.CDrawer canvas);
public void ShowBall(CDrawer GDI_canvas) { GDI_canvas.AddCenteredEllipse(_point.X, _point.Y, _ballRadius*2, _ballRadius*2, Color.FromArgb(BallOpacity, _ballColor)); }
private void Form1_Load(object sender, EventArgs e) { canvas = new CDrawer(bContinuousUpdate:false); canvas.Scale = 10; }
public void ShowBall(CDrawer Canvas) { Canvas.AddCenteredEllipse(_LocationCenter.X,_LocationCenter.Y, _BallRadius,_BallRadius,Color.FromArgb(_BallOpacity, _BallColor.R,_BallColor.G,_BallColor.B)); }
public Form1() { InitializeComponent(); drawer = new CDrawer(800, 600, false); }