private void drawRobotWay(float x, float y)//draw robot way { Pen Line = new Pen(Color.Blue, 2); Graphics plot = CarPosition.CreateGraphics(); float LenghX = ((CarPosition.Width / 2) - 7) / 10; float LenghY = ((CarPosition.Height / 2) - 7) / 10; plot.DrawLine(Line, previousX, previousY, (CarPosition.Width / 2 + (x / 10 * LenghX)), (CarPosition.Height / 2 - (y / 10 * LenghY))); previousX = (CarPosition.Width / 2 + (x / 10 * LenghX)); previousY = (CarPosition.Height / 2 - (y / 10 * LenghY)); }
private void DrawingLine(int _x, int _y) //drawing line betweem center and rectangle { Pen DrawLine = new Pen(Color.Yellow, 3); Graphics plot = CarPosition.CreateGraphics(); float LenghX = ((CarPosition.Width / 2) - 7) / 10; float LenghY = ((CarPosition.Height / 2) - 7) / 10; if (_x >= 0) { plot.DrawLine(DrawLine, CarPosition.Width / 2, CarPosition.Height / 2, (CarPosition.Width / 2 + _x * (int)LenghX), (CarPosition.Height / 2 - _y * (int)LenghY)); } else { plot.DrawLine(DrawLine, CarPosition.Width / 2, CarPosition.Height / 2, (CarPosition.Width / 2 + _x * (int)LenghX) + (int)LenghX, (CarPosition.Height / 2 - _y * (int)LenghY)); } plot.Dispose(); }
private void DrawingRectangle(int _x, int _y) //painting the rectangle acording to coordinats { Pen DrawRec = new Pen(Color.Green); SolidBrush FillRec = new SolidBrush(Color.Green); Graphics plot = CarPosition.CreateGraphics(); float LenghX = ((CarPosition.Width / 2) - 7) / 10; float LenghY = ((CarPosition.Height / 2) - 7) / 10; if (_y >= 0) { Rectangle rect = new Rectangle((CarPosition.Width / 2 + _x * (int)LenghX), (CarPosition.Height / 2 - _y * (int)LenghY) - (int)LenghY, CarPosition.Width / 20 - 1, CarPosition.Height / 20 - 1); plot.DrawRectangle(DrawRec, rect); plot.FillRectangle(FillRec, rect); } else { Rectangle rect = new Rectangle((CarPosition.Width / 2 + _x * (int)LenghX), (CarPosition.Height / 2 - _y * (int)LenghY), CarPosition.Width / 20 - 1, CarPosition.Height / 20 - 1); plot.DrawRectangle(DrawRec, rect); plot.FillRectangle(FillRec, rect); } plot.Dispose(); }
private void DrawingPlot() { Pen PlotLine, ExtraPlotLine; PlotLine = new Pen(Color.Black, 2); ExtraPlotLine = new Pen(Color.Black); Graphics plot = CarPosition.CreateGraphics(); //drawing plot axis plot.DrawLine(PlotLine, 0, CarPosition.Height / 2, CarPosition.Width, CarPosition.Height / 2); plot.DrawLine(PlotLine, CarPosition.Width / 2, 0, CarPosition.Width / 2, CarPosition.Height); //drawing Oy arrow plot.DrawLine(PlotLine, ((CarPosition.Width / 2) - 7), 10, (CarPosition.Width / 2), 0); plot.DrawLine(PlotLine, (CarPosition.Width / 2), 0, ((CarPosition.Width / 2) + 7), 10); //drawimg OX arrow plot.DrawLine(PlotLine, (CarPosition.Width - 10), ((CarPosition.Height / 2) - 7), CarPosition.Width, (CarPosition.Height / 2)); plot.DrawLine(PlotLine, CarPosition.Width, (CarPosition.Height / 2), (CarPosition.Width - 10), ((CarPosition.Height / 2) + 7)); float LenghX = ((CarPosition.Width / 2) - 7) / 10; float LenghY = ((CarPosition.Height / 2) - 7) / 10; Font drawFont = new Font("Arial", 9); SolidBrush drawBrush = new SolidBrush(Color.Black); plot.DrawString("0", drawFont, drawBrush, new PointF(((CarPosition.Width / 2) + 2), (CarPosition.Height / 2) + 2)); plot.DrawString("Y", new Font("Arial", 11), drawBrush, new PointF(((CarPosition.Width / 2) - 22), 2)); plot.DrawString("X", new Font("Arial", 11), drawBrush, new PointF(CarPosition.Width - 15, ((CarPosition.Height / 2) - 22))); float sum = 0; for (int i = 1; i <= 10; i++) { sum = sum + LenghX; //splitting Ox in 10 sections plot.DrawLine(PlotLine, ((CarPosition.Width / 2) + sum), ((CarPosition.Height / 2) + 5), ((CarPosition.Width / 2) + sum), ((CarPosition.Height / 2) - 5)); plot.DrawLine(PlotLine, ((CarPosition.Width / 2) - sum), ((CarPosition.Height / 2) + 5), ((CarPosition.Width / 2) - sum), ((CarPosition.Height / 2) - 5)); //putting the section number plot.DrawString(Convert.ToString(i * 10), drawFont, drawBrush, new PointF(((CarPosition.Width / 2) + sum - 5), ((CarPosition.Height / 2) + 6))); plot.DrawString(Convert.ToString(i * -10), drawFont, drawBrush, new PointF(((CarPosition.Width / 2) - sum - 7), ((CarPosition.Height / 2) + 6))); //drawing extra lines Ox plot.DrawLine(ExtraPlotLine, ((CarPosition.Width / 2) + sum), 0, ((CarPosition.Width / 2) + sum), CarPosition.Height); plot.DrawLine(ExtraPlotLine, ((CarPosition.Width / 2) - sum), 0, ((CarPosition.Width / 2) - sum), CarPosition.Height); } sum = 0; for (int i = 1; i <= 10; i++) { sum = sum + LenghY; //splitting Oy in 10 sections plot.DrawLine(PlotLine, ((CarPosition.Width / 2) - 5), ((CarPosition.Height / 2) + sum), ((CarPosition.Width / 2) + 5), ((CarPosition.Height / 2) + sum)); plot.DrawLine(PlotLine, ((CarPosition.Width / 2) - 5), ((CarPosition.Height / 2) - sum), ((CarPosition.Width / 2) + 5), ((CarPosition.Height / 2) - sum)); //putting the section number plot.DrawString(Convert.ToString(i * 10), drawFont, drawBrush, new PointF(((CarPosition.Width / 2) + 6), ((CarPosition.Height / 2) - sum - 5))); plot.DrawString(Convert.ToString(i * -10), drawFont, drawBrush, new PointF(((CarPosition.Width / 2) + 6), ((CarPosition.Height / 2) + sum - 7))); //drawing extra lines Oy plot.DrawLine(ExtraPlotLine, 0, ((CarPosition.Height / 2) + sum), CarPosition.Width, ((CarPosition.Height / 2) + sum)); plot.DrawLine(ExtraPlotLine, 0, ((CarPosition.Height / 2) - sum), CarPosition.Width, ((CarPosition.Height / 2) - sum)); } plot.Dispose(); }