c语言编程 “画圆” 源程序

本文介绍了如何使用中点Bresenham算法结合Graphics.H和Math.H库在图形界面中绘制圆,并配合坐标轴和表格显示。主要展示了两个关键部分:circlePoint函数和MidBresenhamcircle函数的应用。
摘要由CSDN通过智能技术生成

#include<graphics.h>
void main()
{
int driver,mode;
driver=DETECT;
mode=0;
initgraph(&driver,&mode,“”);
setcolor(25);
line(66,66,88,88);
lineto(200,200);
linerel(36,65);
gainch();
restorecrtmode();
}

#include <math.h>
#include <graphics.h> 预约义库函数
void circlePoint(int x,int y) 八分法画圆程序
{
circle(320 x20,250 y20,3);
circle(320 y20,250 x20,3);
circle(320-y20,250 x20,3);
circle(320-x20,250 y20,3);
circle(320-x20,250 y20,3);
circle(320-x20,250-y20,3);
circle(320-y20,250-x20,3);
circle(320 y20,250-x20,3);
circle(320 x20,250-y20,3);
}
void MidBresenhamcircle(int r) * 中点Bresenham算法画圆的程序 *
{
int x,y,d;
x=0;y=r;d=2-r;* 统计初始值 *
while(x<y)
{ circlePoint(x,y);* 绘制点(x,y)及其在八分圆中的另外7个对称点 *
if(d<0) d =2x 3; 依照毛病项d的判断,决意非最大位移方向上是走仍是不走 * else
{ d =2*(x-y) 5;
y–;
}
x ;
delay(900000);
} * while *
}
main()
{
int i,j,r,graphmode,graphdriver;
detectgraph(&graphdriver,&graphmode);
initgraph(&graphdriver,&graphmode," “);
printf(“中点Bresenhamcircle算法画圆的程序\n”);提示信息
printf(“看重 |r|<=22”);
printf(”\n输入半径值 r:“);
scanf(”%d",&r);
printf(“按随意任性键表现图形…”);
gainch();
cleardevice();
setbkcolor(BLACK);
for(i=20;i<=620;i =20) 使用双循环画点函数画出表格中的纵坐标
for(j=20;j<=560;j )
putpixel(i,j,2);
for(j=20;j<=560;j =20) 使用双循环画点函数画出表格中的横坐标
for(i=20;i<=620;i )
putpixel(i,j,2);
outtextxy(320,255,“0”);原点坐标
outtextxy(320-520,255,“-5”);circle(320-520,250,2);横坐标值
outtextxy(320 520,255,“5”);circle(320 520,250,2);
outtextxy(320-2020,255,“-20”);circle(320-2020,250,2);
outtextxy(320 2020,255,“20”);circle(320 2020,250,2);
outtextxy(320-2520,255,“-25”);circle(320-2520,250,2);
outtextxy(320 2520,255,“25”);circle(320 2520,250,2);
outtextxy(320,250-520,“-5”);circle(320,250-520,2);纵坐标值
outtextxy(320,250 520,“5”);circle(320,250 520,2);
outtextxy(320,250-2020,“-20”);circle(320,250-2020,2);
outtextxy(320,250 2020,“20”);circle(320,250 2020,2);
outtextxy(20,20,“The center of the circle is (0,0) “);坐标轴左上角表现提示信息 setcolor(RED);标记坐标轴
line(20,250,620,250);outtextxy(320 2520,230,“X”);
line(320,20,320,560);outtextxy(330,20,“Y”);
setcolor(YELLOW);
MidBresenhamcircle(r);
setcolor(BLUE);绘制圆
circle(320,250,r
20);
setcolor(2);
gainch();
closegraph();
}
--------------------------------------------------------#include<graphics.h>
void main()
{
int driver,mode;
driver=DETECT;
mode=0;
initgraph(&driver,&mode,””);
setcolor(25);
circle(20,20,20);
gainch();
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zxbyzx

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值