139.图形法绘制圆
【摘要】
#include <stdio.h>#include <graphics.h>#include <dos.h>/*这是根据给出的圆心坐标和点坐标分别在八个象限画点的子程序*/void circlePoint( int xCenter, int yCenter, int x, int y ){ putp...
-
#include <stdio.h>
-
#include <graphics.h>
-
#include <dos.h>
-
/*这是根据给出的圆心坐标和点坐标分别在八个象限画点的子程序*/
-
void circlePoint( int xCenter, int yCenter, int x, int y )
-
{
-
putpixel( xCenter + x, yCenter + y, YELLOW );
-
putpixel( xCenter - x, yCenter + y, YELLOW );
-
putpixel( xCenter + x, yCenter - y, YELLOW );
-
putpixel( xCenter - x, yCenter - y, YELLOW );
-
putpixel( xCenter + y, yCenter + x, YELLOW );
-
putpixel( xCenter - y, yCenter + x, YELLOW );
-
putpixel( xCenter + y, yCenter - x, YELLOW );
-
putpixel( xCenter - y, yCenter - x, YELLOW );
-
}
-
-
void myCircle(int xCenter,int yCenter,int radius)
-
{
-
int x, y, p;
-
/*初始化各个参数*/
-
x = 0;
-
y = radius;
-
p = 1 - radius;
-
circlePoint(xCenter, yCenter, x, y);
-
/*循环中计算圆上的各点坐标*/
-
while( x < y ) {
-
x++;
-
if( p < 0 )
-
p += 2*x+1;
-
else
-
{
-
y--;
-
p+=2*(x-y)+1;
-
}
-
circlePoint( xCenter, yCenter, x, y);
-
}
-
}
-
-
void main()
-
{
-
int gdriver=DETECT, gmode; /*这是用c画图时必须要使用的图像入口*/
-
int i;
-
int xCenter, yCenter, radius;
-
printf("Please input center coordinate :(x,y) ");
-
scanf("%d,%d", &xCenter, &yCenter );
-
printf("Please input radius : ");
-
scanf("%d", &radius );
-
/*这条语句初始化整个屏幕并把入口传给gdriver,注意引号中是tc中bgi目录的完整路径*/
-
registerbgidriver(EGAVGA_driver);
-
initgraph(&gdriver, &gmode, "..\\bgi");
-
setcolor( BLUE );
-
myCircle(xCenter, yCenter, radius);
-
sleep(3);
-
closegraph();
-
return;
-
}
文章来源: blog.csdn.net,作者:程序员编程指南,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_41055260/article/details/124665484
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)