do hoa may tinh ve duong thang va duong tron
using System;
using System.Collections.Generic;
using System.Text;
using CsGL.Basecode;
using System.Drawing;
namespace Lab3
{
class OpenGL:Model
{
public override void Initialize()
{
base.Initialize();
}
public override void Draw()
{
base.Draw();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3f(1,0,1);
glPointSize(3);
glBegin(GL_POINTS);
//BRLine(new Point(10, 100), new Point(200, 100));
Point O = new Point(90, 55);
Circle(O, 100);
for (int i = -200; i <= 200; i++)
{
glVertex2i(0, i);
glVertex2i(i, 0);
}
ToMauDgTron();
glVertex2i(100, 100);
glEnd();
}
private void ToMauDgTron()
{
//throw new Exception("The method or operation is not implemented.");
}
public static void Circle(Point O, int R)
{
int x, y, d;
x = 0; y = R;
d = 1 - R;
CirclePoints(new Point(x, y), O);
while (y > x)
{
if (d < 0)
{
d += 2 * x + 3;
}
else
{
d += 2 * (x - y) + 5;
y--;
}
x++;
CirclePoints(new Point(x, y), O);
}
}
public static void CirclePoints(Point P,Point O)
{
glVertex2i(P.X + O.X, P.Y +O.Y );
glVertex2i(P.Y + O.X, P.X + O.Y);
glVertex2i(-P.X + O.X, -P.Y + O.Y);
glVertex2i(-P.Y + O.X, -P.X + O.Y);
glVertex2i(-P.X + O.X, P.Y + O.Y);
glVertex2i(-P.Y + O.X, P.X + O.Y);
glVertex2i(P.X + O.X, -P.Y + O.Y);
glVertex2i(P.Y + O.X, -P.X + O.Y);
}
public static void ToMauDgTron(Point P, Point O)
{
BRLine(new Point( P.X, P.Y ),new Point(-P.X, P.Y));
BRLine(new Point( P.Y, P.X),new Point(-P.Y, P.X));
BRLine(new Point(-P.X, -P.Y),new Point(-P.X, -P.Y));
BRLine(new Point(-P.Y, -P.X), new Point(-P.Y, -P.X));
}
public static void BRLine(Point a, Point b)
{
int x = a.X, y = a.Y, x1 = b.X - a.X, y1 = b.Y - a.Y, p = 2 * y1 - x1;
while (x<= b.X)
{
glVertex2i(x, y);
if (p <= 0) p += 2 * y1;
else
{
y++;
p += 2 * y1 - 2 * x1;
}
x++;
}
}
}
}
Bạn đang đọc truyện trên: AzTruyen.Top