Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using System.Linq;
- using OpenTK.Graphics.OpenGL;
- using System.Windows.Forms;
- namespace КГГ_1
- {
- public partial class MainForm : Form
- {
- private double MinY, MaxY;
- public MainForm()
- {
- InitializeComponent();
- }
- private double A= 2 , B = 5;
- private int WR, HR;
- private double F(double x)
- {
- return 20-x*Math.Sin(x*x);
- }
- private void MainForm_Load(object sender, EventArgs e)
- {
- }
- private void glc_Resize(object sender, EventArgs e)
- {
- GL.ClearColor(Color.White);
- WR = glc.Width;
- HR = glc.Height;
- GL.MatrixMode(MatrixMode.Projection);
- GL.LoadIdentity();
- GL.Ortho(0, WR, 0, HR, -1, 1); // Bottom-left corner pixel has coordinate (0, 0)
- GL.Viewport(0, 0, WR, HR); // Use all of the glControl painting area
- glc.Invalidate();
- }
- private void glc_Paint(object sender, PaintEventArgs e)
- {
- var values = new double[WR];
- for (var i = 0; i < WR; ++i)
- {
- values[i] = F(i*(B - A)/WR + A);
- }
- MinY = values.Min();
- MaxY = values.Max();
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- GL.LineWidth(1);
- GL.Color3(Color.Red);
- GL.Begin(BeginMode.LineStrip);
- for (var i = 0; i < WR; ++i)
- {
- DrawPoint(i, values[i]);
- }
- GL.End();
- GL.LineWidth(1);
- GL.Color3(Color.Black);
- GL.Begin(BeginMode.Lines);
- if (MinY <= 0 && 0 <= MaxY)
- {
- DrawPoint(0, 0);
- DrawPoint(WR, 0);
- }
- if (A <= 0 && 0 <= B)
- {
- GL.Vertex2((-A)*WR/(B - A), 0);
- GL.Vertex2((-A)*WR/(B - A), HR);
- }
- GL.End();
- glc.SwapBuffers();
- }
- private void DrawPoint(int x, double y)
- {
- GL.Vertex2(x, (y-MinY)*HR/(MaxY-MinY));
- }
- private void glc_Load(object sender, EventArgs e)
- {
- GL.ClearColor(Color.White);
- WR = glc.Width;
- HR = glc.Height;
- GL.MatrixMode(MatrixMode.Projection);
- GL.LoadIdentity();
- GL.Ortho(0, WR, 0, HR, -1, 1); // Bottom-left corner pixel has coordinate (0, 0)
- GL.Viewport(0, 0, WR, HR); // Use all of the glControl painting area
- glc.Invalidate();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement