public Bitmap Paint(CoordinatePlane space) { Bitmap bitmap = new Bitmap((int)space.Size.X, (int)space.Size.Y); Graphics draw = Graphics.FromImage(bitmap); Axis size = space.GridSize; Axis center = space.Center; float x1, y1, x2, y2; List <Axis> .Enumerator enumerator = _dots.GetEnumerator(); enumerator.MoveNext(); x1 = (enumerator.Current.X + center.X) * size.X; y1 = (center.Y - enumerator.Current.Y) * size.Y; for (int i = 1; i < _dots.Count; i++) { enumerator.MoveNext(); x2 = (enumerator.Current.X + center.X) * size.X; y2 = (center.Y - enumerator.Current.Y) * size.Y; try { draw.DrawLine(Pen, x1, y1, x2, y2); } catch { } x1 = x2; y1 = y2; } return(bitmap); }
private void cubicGraph(object sender, EventArgs e) { Graphics g = CoordinatePlane.CreateGraphics(); if ((string)cubicColor.SelectedValue == "White") { selectedPen = new Pen(Color.White); } else if ((string)cubicColor.SelectedValue == "Red") { selectedPen = new Pen(Color.Red); } else if ((string)cubicColor.SelectedValue == "Green") { selectedPen = new Pen(Color.Green); } else if ((string)cubicColor.SelectedValue == "Blue") { selectedPen = new Pen(Color.Blue); } List <PointF> pointList = new List <PointF>(); //create list of points float xMinR = Convert.ToSingle(xMinRange.Value); //gets min x range and scales it to picture box float xMaxR = Convert.ToSingle(xMaxRange.Value); //gets max x range and scales it to picture box float AbsXMinR = Math.Abs(xMinR); //gets absolute value of MinRangeX float AbsXMaxR = Math.Abs(xMaxR); //gets absolute value of MaxRangeX float yMinR = Convert.ToSingle(yMinRange.Value); //gets min y range and scales it to picture box float yMaxR = Convert.ToSingle(yMaxRange.Value); //gets max y range and scales it to picture box float AbsYMinR = Math.Abs(yMinR); float AbsYMaxR = Math.Abs(yMaxR); float scaleModX = (AbsXMinR + AbsXMaxR) / 2; float scaleModY = (AbsYMinR + AbsYMaxR) / 2; float scale = CoordinatePlane.Height / (AbsXMaxR + AbsXMinR); float a = Convert.ToSingle(cubicA.Text) * scale; float b = Convert.ToSingle(cubicB.Text) * scale; float c = Convert.ToSingle(cubicC.Text) * scale; float d = Convert.ToSingle(cubicD.Text) * scale; //loops through the range of xmin to xmax for (float x = xMinR; x < xMaxR; x++) { //cubic equation a,b,c,d are pulled from user entries float y = ((a * (x * x * x) + (b * (x * x) + (c * x) + d))); pointList.Add(new PointF((scale * scaleModX) + x * scale, (scale * AbsXMaxR) - y)); } PointF[] pointArray = pointList.ToArray(); g.DrawCurve(selectedPen, pointArray); }
public Bitmap Paint(CoordinatePlane space) { Bitmap bitmap = new Bitmap((int)space.Size.X, (int)space.Size.Y); Graphics draw = Graphics.FromImage(bitmap); draw.DrawLine(Pen, space.Center.X * space.GridSize.X, 0, space.Center.X * space.GridSize.X, space.Size.Y); draw.DrawLine(Pen, 0, space.Center.Y * space.GridSize.Y, space.Size.X, space.Center.Y * space.GridSize.Y); return(bitmap); }
public Bitmap Paint(CoordinatePlane space) { Bitmap bitmap = new Bitmap((int)space.Size.X, (int)space.Size.Y); Graphics draw = Graphics.FromImage(bitmap); for (float i = 0; i < space.Size.X; i += space.GridSize.X) { draw.DrawLine(Pen, i, 0, i, space.Size.Y); } for (float i = 0; i < space.Size.Y; i += space.GridSize.Y) { draw.DrawLine(Pen, 0, i, space.Size.X, i); } return(bitmap); }
private void clearGraph(object sender, EventArgs e) { Graphics g = CoordinatePlane.CreateGraphics(); xMin = Convert.ToInt32(xMinRange.Value); xMax = Convert.ToInt32(xMaxRange.Value); yMin = Convert.ToInt32(yMinRange.Value); yMax = Convert.ToInt32(yMaxRange.Value); SolidBrush paintItBlack = new SolidBrush(Color.Black); g.FillRectangle(paintItBlack, 0, 0, CoordinatePlane.Width, CoordinatePlane.Height); //Horizontal Axis g.DrawLine(whitePen, 0, (float)yMax * (600 / ((float)yMax - (float)yMin)), CoordinatePlane.Width, (float)yMax * (600 / ((float)yMax - (float)yMin))); //Vertical Axis g.DrawLine(whitePen, (float)Math.Abs(xMin) * (600 / ((float)xMax - (float)xMin)), 0, (float)Math.Abs(xMin) * (600 / ((float)xMax - (float)xMin)), CoordinatePlane.Height); }
private void quadGraph(object sender, EventArgs e) { Graphics g = CoordinatePlane.CreateGraphics(); if ((string)quadColor.SelectedValue == "White") { selectedPen = new Pen(Color.White); } else if ((string)quadColor.SelectedValue == "Red") { selectedPen = new Pen(Color.Red); } else if ((string)quadColor.SelectedValue == "Green") { selectedPen = new Pen(Color.Green); } else if ((string)quadColor.SelectedValue == "Blue") { selectedPen = new Pen(Color.Blue); } List <PointF> pointList = new List <PointF>(); float xMinR = Convert.ToSingle(xMinRange.Value); //gets min x range and scales it to picture box float xMaxR = Convert.ToSingle(xMaxRange.Value); //gets max x range and scales it to picture box float AbsXMinR = Math.Abs(xMinR); float AbsXMaxR = Math.Abs(xMaxR); float scale = CoordinatePlane.Height / (AbsXMaxR + AbsXMinR); float a = Convert.ToSingle(quadA.Text) * scale; float b = Convert.ToSingle(quadB.Text) * scale; float c = Convert.ToSingle(quadC.Text) * scale; //loops through the range of xmin to xmax for (float x = xMinR; x < xMaxR; x++) { //quad equation a,b,c,d are pulled from user entries float y = (a * (x * x) + (b * x + c)); pointList.Add(new PointF((scale * AbsXMinR) + x * scale, (scale * AbsXMaxR) - y)); } PointF[] pointArray = pointList.ToArray(); g.DrawCurve(selectedPen, pointArray); }
private void circleGraph(object sender, EventArgs e) { Graphics g = CoordinatePlane.CreateGraphics(); //handles color selction if ((string)circleColor.SelectedValue == "White") { selectedPen = new Pen(Color.White); } else if ((string)circleColor.SelectedValue == "Red") { selectedPen = new Pen(Color.Red); } else if ((string)circleColor.SelectedValue == "Green") { selectedPen = new Pen(Color.Green); } else if ((string)circleColor.SelectedValue == "Blue") { selectedPen = new Pen(Color.Blue); } float xMinR = Convert.ToSingle(xMinRange.Value); //gets min x range and scales it to picture box float xMaxR = Convert.ToSingle(xMaxRange.Value); //gets max x range and scales it to picture box float AbsXMinR = Math.Abs(xMinR); float AbsXMaxR = Math.Abs(xMaxR); float yMinR = Convert.ToSingle(yMinRange.Value); //gets min x range and scales it to picture box float yMaxR = Convert.ToSingle(yMaxRange.Value); //gets max x range and scales it to picture box float AbsYMinR = Math.Abs(yMinR); float AbsYMaxR = Math.Abs(yMaxR); float scaleModX = (AbsXMinR + AbsXMaxR) / 2; float scaleModY = (AbsYMinR + AbsYMaxR) / 2; float scaleX = CoordinatePlane.Height / (AbsXMaxR + AbsXMinR); float scaleY = CoordinatePlane.Height / (AbsYMinR + AbsYMaxR); float h = Convert.ToSingle(circleH.Text) * scaleX; float k = Convert.ToSingle(circleK.Text) * scaleY; double tempR = Convert.ToSingle(circleR.Text); float r = (float)Math.Sqrt(tempR) * scaleX; //scales the radius g.DrawEllipse(selectedPen, h + (scaleModX * scaleX) - r, (scaleY * scaleModY) - k - r, r * 2, r * 2); //draws ellipse }
public Bitmap Paint(CoordinatePlane space) { Bitmap bitmap = new Bitmap((int)space.Size.X, (int)space.Size.Y); Graphics draw = Graphics.FromImage(bitmap); Axis size = space.GridSize; Axis center = space.Center; float len = Pen.Width / 2f; foreach (var dot in _dots) { try { draw.DrawEllipse(Pen, ((dot.X + center.X) * size.X) - len, ((center.Y - dot.Y) * size.Y) - len, Pen.Width, Pen.Width); } catch { } } return(bitmap); }
private void linearGraph(object sender, EventArgs e) { Graphics g = CoordinatePlane.CreateGraphics(); if ((string)linearColor.SelectedValue == "White") { selectedPen = new Pen(Color.White); } else if ((string)linearColor.SelectedValue == "Red") { selectedPen = new Pen(Color.Red); } else if ((string)linearColor.SelectedValue == "Green") { selectedPen = new Pen(Color.Green); } else if ((string)linearColor.SelectedValue == "Blue") { selectedPen = new Pen(Color.Blue); } float m = float.Parse(linearM.Text); float b = float.Parse(linearB.Text); float y = (float)yMax; float x1; float x2; float y1; float y2; if (m != 0) { y1 = y; x1 = (y - b) / m; if (x1 < (float)xMin) { x1 = (float)xMin; y1 = (m * x1) + b; } x1 = Convert_X_Point(x1); y1 = Convert_Y_Point(y1); //Find the second point y = (float)yMin; y2 = y; x2 = (y - b) / m; if (x2 > (float)xMax) { x2 = (float)xMax; y2 = (m * x2) + b; } x2 = Convert_X_Point(x2); y2 = Convert_Y_Point(y2); } else { x1 = 0; y1 = b; x2 = CoordinatePlane.Width; y2 = b; y1 = Convert_Y_Point(y1); y2 = Convert_Y_Point(y2); } g.DrawLine(selectedPen, x1, y1, x2, y2); }