using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Tao.OpenGl;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
Application.Idle += new EventHandler(Application_Idle);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Glu.gluOrtho2D(2, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height, 5);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
polyA = new List<PointF>();
polyB = new List<PointF>();
Gl.glPointSize(10);
Gl.glClearColor(0, 0, 0, 0);
}
float i = 0;
void Application_Idle(object sender, EventArgs e)
{
simpleOpenGlControl1.Invalidate();
}
List<PointF> polyA;
List<PointF> polyB;
private void simpleOpenGlControl1_MouseClick(object sender, MouseEventArgs e)
{
if (radioButton1.Checked)
{
polyA.Add(new PointF(e.X, e.Y));
updateAPoints();
}
else
{
polyB.Add(new PointF(e.X, e.Y));
updateBPoints();
}
}
public void updateAPoints()
{
//label1.Text = "Points in A: " + polyA.Count;
}
public void updateBPoints()
{
label2.Text = "Points in B: " + polyB.Count;
}
bool startTween = false;
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
if (!startTween)
{
drawLines();
}
else
{
drawTween(polyA, polyB, i);
}
}
public void drawTween(List<PointF> A, List<PointF> B,float t)
{
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(1, 1, 1);
PointF p2=new PointF();
for (int i = 0; i < polyA.Count; i++)
{
p2.X = (1-t)*polyA[i].X+t*(polyB[i].X);
p2.Y = (1 - t) * polyA[i].Y + t * (polyB[i].Y);
Gl.glVertex3f(p2.X, p2.Y, 0);
}
Gl.glEnd();
}
public void drawLines()
{
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(4,5,0);
for (int i = 0; i < polyA.Count; i++)
{
Gl.glVertex3f(polyA[i].X, polyA[i].Y, 0);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(6, 0, 1);
for (int i = 0; i < polyB.Count; i++)
{
Gl.glVertex3f(polyB[i].X, polyB[i].Y, 0);
}
Gl.glEnd();
Gl.glFlush();
}
private void button1_Click(object sender, EventArgs e)
{
startTween = true;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
updateTweenTime();
}
public void updateTweenTime()
{
i += 0.2f;
if (i > 1)
{
startTween = false;
i = 0;
timer1.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
polyA.Clear();
updateAPoints();
}
private void button3_Click(object sender, EventArgs e)
{
polyB.Clear();
updateBPoints();
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Tao.OpenGl;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
Application.Idle += new EventHandler(Application_Idle);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Glu.gluOrtho2D(2, simpleOpenGlControl1.Width, simpleOpenGlControl1.Height, 5);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
polyA = new List<PointF>();
polyB = new List<PointF>();
Gl.glPointSize(10);
Gl.glClearColor(0, 0, 0, 0);
}
float i = 0;
void Application_Idle(object sender, EventArgs e)
{
simpleOpenGlControl1.Invalidate();
}
List<PointF> polyA;
List<PointF> polyB;
private void simpleOpenGlControl1_MouseClick(object sender, MouseEventArgs e)
{
if (radioButton1.Checked)
{
polyA.Add(new PointF(e.X, e.Y));
updateAPoints();
}
else
{
polyB.Add(new PointF(e.X, e.Y));
updateBPoints();
}
}
public void updateAPoints()
{
//label1.Text = "Points in A: " + polyA.Count;
}
public void updateBPoints()
{
label2.Text = "Points in B: " + polyB.Count;
}
bool startTween = false;
private void simpleOpenGlControl1_Paint(object sender, PaintEventArgs e)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
if (!startTween)
{
drawLines();
}
else
{
drawTween(polyA, polyB, i);
}
}
public void drawTween(List<PointF> A, List<PointF> B,float t)
{
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(1, 1, 1);
PointF p2=new PointF();
for (int i = 0; i < polyA.Count; i++)
{
p2.X = (1-t)*polyA[i].X+t*(polyB[i].X);
p2.Y = (1 - t) * polyA[i].Y + t * (polyB[i].Y);
Gl.glVertex3f(p2.X, p2.Y, 0);
}
Gl.glEnd();
}
public void drawLines()
{
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(4,5,0);
for (int i = 0; i < polyA.Count; i++)
{
Gl.glVertex3f(polyA[i].X, polyA[i].Y, 0);
}
Gl.glEnd();
Gl.glBegin(Gl.GL_LINE_STRIP);
Gl.glColor3f(6, 0, 1);
for (int i = 0; i < polyB.Count; i++)
{
Gl.glVertex3f(polyB[i].X, polyB[i].Y, 0);
}
Gl.glEnd();
Gl.glFlush();
}
private void button1_Click(object sender, EventArgs e)
{
startTween = true;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
updateTweenTime();
}
public void updateTweenTime()
{
i += 0.2f;
if (i > 1)
{
startTween = false;
i = 0;
timer1.Stop();
}
}
private void button2_Click(object sender, EventArgs e)
{
polyA.Clear();
updateAPoints();
}
private void button3_Click(object sender, EventArgs e)
{
polyB.Clear();
updateBPoints();
}
}
}
Computer Graphice C# Twin coding