//包含头文件这个不用我说了吧
#include
#include
#include
#include
//交换a,b的值函数
void Swap(int *a,int *b);
//Bresenhen画园函数,圆心坐标(centerx,centery)半径radius线条颜色color
void BresenhemCircle(int centerx, int centery, int radius, int color, int type);
void initgr(void) /* BGI初始化 */
{
int gd = DETECT, gm = 0; /* 和gd = VGA,gm = VGAHI是同样效果 */
registerbgidriver(EGAVGA_driver);/* 注册BGI驱动后可以不需要.BGI文件的支持运行 */
initgraph(&gd, &gm, "");//初始化图形,必须写的
setbkcolor(WHITE);//设置背景颜色
}
int main(void)
{
int centerx,centery,radius,color,type;//变量定义总该知道的吧
printf("centerx,centery\n");//输出提示信息,这个总该知道的吧
scanf("%d",¢erx);//输入中心坐标横坐标
scanf("%d",¢ery);//
printf("radius\n");
scanf("%d",&radius);
printf("color,type\n");
scanf("%d",&color);
scanf("%d",&type);
initgr(); /*BGI初始化 */
BresenhemCircle(centerx,centery,radius,color,type);//重点理解这个函数
/*setcolor(RED);
circle(centerx, centery,radius);*/
/*Swap(&xs,&xe);
printf("%d,%d",xs,xe); */
getch();
closegraph();
}
void BresenhemCircle(int centerx, int centery, int radius, int color, int type)
{
int x =type= 0;//这些赋值语句应该能够看懂的吧
int y = radius;
int delta = 2*(1-radius);
int direction;
while (y >= 0) {//循环,如果y>=0就继续执行{}里面的语句
if (!type) { //!type表示如果type=0就执行{}里面的语句
putpixel(centerx+x, centery+y, color);
//前面两个参数是坐标,后面一个是颜色值,在(centerx+x, centery+y)画一个点
putpixel(centerx-x, centery+y, color);
putpixel(centerx-x, centery-y, color);
putpixel(centerx+x, centery-y, color);
}
else {//如果type=1就执行下面的
line(centerx+x, centery+y, centerx+x, centery-y);
line(centerx-x, centery+y, centerx-x, centery-y);
}
if (delta < 0) {//这个类似上面的,只不过这个嵌套了一层if-else if-else
if ((2*(delta+y)-1) < 0) {
direction = 1;
}
else {
direction = 2;
}
}
else if(delta > 0) {
if ((2*(delta-x)-1) <= 0) {
direction = 2;
}
else {
direction = 3;
}
}
else {
direction=2;
}
switch(direction) {//选择如果direction=1执行case 1:到case 2:直接的语句,如果没有break那么case 2:下面的语句也会被执行
case 1:
x++;
delta += (2*x+1);
break;
case 2:
x++;
y--;
delta += 2*(x-y+1);
break;
case 3:
y--;
delta += (-2*y+1);
break;
}
}
}
强烈推荐你看看这个,我的原创:http://tieba.baidu.com/f?kz=778031710
里面十分简单的讲了怎样用vc绘图,一看就懂。之后,把Bresenhem算法套进去就行
这些不用说吧,上QQ我直接给你翻译