Code:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#define PATH "D:\\BORLANDC\\BGI"
void LineBres(int x1, int y1, int x2, int y2,int color)
{
int Dx, Dy, p, Const1, Const2;
int x, y;
int i;
Dx = x2 - x1;
Dy = y2 - y1;
p = 2*Dy - Dx; // Dy <<1 - Dx
Const1 = 2*Dy; // Dy <<1
Const2 = 2*(Dy-Dx); // (Dy-Dx) <<1
x = x1;
y = y1;
putpixel(x, y,color);
for(i=x1; i<x2; i++)
{
if (p<0)
p += Const1;
else
{
p += Const2;
y++;
}
x++;
putpixel(x, y,color);
}
} // LineBres
void main()
{
int mh,mode;
mh=mode=0;
initgraph(&mh,&mode,PATH);
LineBres(200,100,300,450,WHITE);
getch();
closegraph();
}
Mình vẽ ra đường gấp khúc ??? >.< . Bạn nào rành xin chỉ bảo giùm . Thanks