private void button1_Click(object sender, EventArgs e) { GraphicRepresentation frm = new GraphicRepresentation(); GraphicPainter painter = new GraphicPainter(); painter.DrawElement = frm.pictureBoxToDraw; ConfigurePainter(ref painter, currentIndex); frm.CurrentPainter = painter; frm.Show(); }
private void ConfigurePainter(ref GraphicPainter painter, int currentIndex) { try { double a = Convert.ToDouble(textBox1.Text), b = Convert.ToDouble(textBox2.Text); int n = Convert.ToInt32(numericUpDown1.Value); ConfigureBounds(ref painter, a, b); painter.Draw(func, GetRandColor(), (float)width); DrawCurrentRegion(ref painter, currentIndex, a, b, n); } catch (InvalidCastException exp) { MessageBox.Show(exp.Message); } }
private void ConfigureBounds(ref GraphicPainter painter, double a, double b) { double maxF = func.MaxValue(a, b, false), minF = func.MinValue(a, b, false); double x, y, x1, y1; if (a < 0) { x = a - 1; } else { x = -1; } if (b < 0) { x1 = 1; } else { x1 = b + 1; } if (maxF < 0) { y1 = 1; } else { y1 = maxF + 1; } if (minF > 0) { y = -1; } else { y = minF - 1; } painter.XBounds = new Point((int)x - 1, (int)x1 + 1); painter.YBounds = new Point((int)y - 1, (int)y1 + 1); }
private void DrawCurrentRegion(ref GraphicPainter painter, int currentIndex, double a, double b, int n) { switch (currentIndex) { case 0: painter.DrawPath(painter.PathForRectangularMethod(func, RectangularMethodType.Left, a, b, n), GetRandColor(), (float)width, GetRandColor(), alpha); break; case 1: painter.DrawPath(painter.PathForRectangularMethod(func, RectangularMethodType.Right, a, b, n), GetRandColor(), (float)width, GetRandColor(), alpha); break; case 2: painter.DrawPath(painter.PathForRectangularMethod(func, RectangularMethodType.Central, a, b, n), GetRandColor(), (float)width, GetRandColor(), alpha); break; case 3: painter.DrawPath(painter.PathForTrapezoidMethod(func, a, b, n), GetRandColor(), (float)width, GetRandColor(), alpha); break; case 4: painter.DrawPath(painter.PathForSimpsonMethod(func, a, b, n), GetRandColor(), (float)width, GetRandColor(), alpha); break; case 6: painter.DrawPath(painter.PathForFunction(func, a, b), GetRandColor(), (float)width, GetRandColor(), alpha); break; default: break; } }