Advertisement
RaWRCoder

КГГ1

Nov 6th, 2015
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Drawing;
  3. using System.Linq;
  4. using OpenTK.Graphics.OpenGL;
  5. using System.Windows.Forms;
  6.  
  7. namespace КГГ_1
  8. {
  9.     public partial class MainForm : Form
  10.     {
  11.         private double MinY, MaxY;
  12.         public MainForm()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.        
  17.         private double A= 2 , B = 5;
  18.         private int WR, HR;
  19.         private double F(double x)
  20.         {
  21.             return 20-x*Math.Sin(x*x);
  22.         }
  23.  
  24.         private void MainForm_Load(object sender, EventArgs e)
  25.         {
  26.  
  27.         }
  28.  
  29.         private void glc_Resize(object sender, EventArgs e)
  30.         {
  31.             GL.ClearColor(Color.White);
  32.             WR = glc.Width;
  33.             HR = glc.Height;
  34.             GL.MatrixMode(MatrixMode.Projection);
  35.             GL.LoadIdentity();
  36.             GL.Ortho(0, WR, 0, HR, -1, 1); // Bottom-left corner pixel has coordinate (0, 0)
  37.             GL.Viewport(0, 0, WR, HR); // Use all of the glControl painting area
  38.             glc.Invalidate();
  39.         }
  40.  
  41.         private void glc_Paint(object sender, PaintEventArgs e)
  42.         {
  43.             var values = new double[WR];
  44.             for (var i = 0; i < WR; ++i)
  45.             {
  46.                 values[i] = F(i*(B - A)/WR + A);
  47.             }
  48.             MinY = values.Min();
  49.             MaxY = values.Max();
  50.  
  51.             GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
  52.             GL.LineWidth(1);
  53.             GL.Color3(Color.Red);
  54.             GL.Begin(BeginMode.LineStrip);
  55.             for (var i = 0; i < WR; ++i)
  56.             {
  57.                 DrawPoint(i, values[i]);
  58.             }
  59.             GL.End();
  60.  
  61.             GL.LineWidth(1);
  62.             GL.Color3(Color.Black);
  63.             GL.Begin(BeginMode.Lines);
  64.             if (MinY <= 0 && 0 <= MaxY)
  65.             {
  66.                 DrawPoint(0, 0);
  67.                 DrawPoint(WR, 0);
  68.             }
  69.             if (A <= 0 && 0 <= B)
  70.             {
  71.                 GL.Vertex2((-A)*WR/(B - A), 0);
  72.                 GL.Vertex2((-A)*WR/(B - A), HR);
  73.             }
  74.             GL.End();
  75.             glc.SwapBuffers();
  76.         }
  77.  
  78.         private void DrawPoint(int x, double y)
  79.         {
  80.             GL.Vertex2(x, (y-MinY)*HR/(MaxY-MinY));
  81.         }
  82.  
  83.         private void glc_Load(object sender, EventArgs e)
  84.         {
  85.             GL.ClearColor(Color.White);
  86.             WR = glc.Width;
  87.             HR = glc.Height;
  88.             GL.MatrixMode(MatrixMode.Projection);
  89.             GL.LoadIdentity();
  90.             GL.Ortho(0, WR, 0, HR, -1, 1); // Bottom-left corner pixel has coordinate (0, 0)
  91.             GL.Viewport(0, 0, WR, HR); // Use all of the glControl painting area
  92.             glc.Invalidate();
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement