// render graphic of selected function private void Classic_Render(Pen pen_plotter, float x0, float x1, cPlotFunction PlotFunction) { double x_last = x0; double y_last = PlotFunction.plotArray[0]; double dx = (x1 - x0) / (100 * 2); double x = x_last; foreach (double y in PlotFunction.plotArray) { // pass the first itteration, because we want get coords only for start point now if (x != x_last) { hwnd.DrawLine(pen_plotter, (int)x_last, (int)y_last, (int)x, (int)y); } y_last = y; x_last = x; x += dx; } }
private void button1_Click(object sender, EventArgs e) { /* * 1. Sin (x) * 2. Cos (x) * 3. Sin (x) + Sin (2x) * 4. Sin (x) - Sin (2x) * 5. Sin (x) + Cos (2x) * 6. Sin (x) - Cos (2x) * 7. Sin (x) * Exp (x) * 8. Cos (x) * Exp (x) * 9. Sin (x) * Exp (-x) * 10. Cos (x) * Exp (-x) */ // init class cPlotFunction cPlotFunction PlotFunction = new cPlotFunction(); // Clean window hwnd.Clear(this.BackColor); // Select a color of pen Pen pen_border = Pens.Black; Pen pen_axis = Pens.Gray; Pen pen_plotter = Pens.DarkBlue; // Caption string s = comboBox1.SelectedItem.ToString(); int uptab = 25; int downtab = 40; int lefttab = 10; int righttab = 10; float amplitude = (this.Height - uptab - downtab) / 2; float x0 = lefttab; float y0 = uptab;//this.Height / 2; float x1 = this.Width - righttab; float y1 = this.Height - downtab; float y_center = (this.Height - uptab - downtab) / 2 + uptab; // Draw info hwnd.DrawString(s, new Font("Arial", 14), Brushes.Red, x0, y1 + 5); // plot axis // hwnd.DrawLine(pen, x0, y0, x1, y0); //hwnd.DrawLine(pen, x0, y0 - amplitude, x0, y0 + amplitude); // Draw Borders hwnd.DrawLine(pen_border, x0, y0, x0, y1); hwnd.DrawLine(pen_border, x0, y1, x1, y1); hwnd.DrawLine(pen_border, x1, y1, x1, y0); hwnd.DrawLine(pen_border, x1, y0, x0, y0); // Draw Axis hwnd.DrawLine(pen_axis, x0, y_center, x1, y_center); hwnd.DrawLine(pen_axis, x0, y0, x0, y1); cPlotFunction.sWindow my_window; // var for struct that is contain coordinates of drawing field my_window.left = lefttab; my_window.top = uptab; my_window.width = this.Width - lefttab - righttab; my_window.height = this.Height - uptab - downtab; // Draw selected function in ComboBox PlotFunction.Draw(my_window, comboBox1.SelectedItem.ToString()); // render graphic in old way. You can uncomment and see that is the same //Classic_Render(x0, x1, PlotFunction); // render graphic to new way hwnd.DrawLines(pen_plotter, PlotFunction.plotArraySDP); }