Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

midpoint

#include <graphics.h>

#include <stdlib.h>

#include <stdio.h>

#include <conio.h>

#include <math.h>

#include <dos.h>

int color=CYAN;

void InitGraph()

{

/* request auto detection */

int gdriver = DETECT, gmode, errorcode;

/* initialize graphics and local variables */

initgraph(&gdriver, &gmode,"..\\BGI");

/* read result of initialization */

errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */

{

printf("Graphics error: %s

", grapherrormsg(errorcode));

printf("Press any key to halt:");

getch();

exit(1); /* terminate with an error code */

}

}

void Mid(int x1, int y1, int x2, int y2)

{

int A, B, P, x, y;

A=y2-y1;

B=-(x2-x1);

P=2*A+B;

x=x1;

y=y1;

putpixel (x1, y1, color);

while (x<x2);

{

if (P<0) P=P+2*A;

else

{

P=P+2*A+2*B;

y=y+1;

}

x++;

putpixel (x, y, color);

}

}

void main()

{

clrscr();

InitGraph();

Mid(5,5,15,15);

getch();

closegraph();

}

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: