6个回答
推荐于2018-03-11
展开全部
#include <math.h>
#include <graphics.h> /*预定义库函数*/
void circlePoint(int x,int y) /*八分法画圆程序*/
{
circle(320+x*20,240+y*20,3);
circle(320+y*20,240+x*20,3);
circle(320-y*20,240+x*20,3);
circle(320-x*20,240+y*20,3);
circle(320-x*20,240+y*20,3);
circle(320-x*20,240-y*20,3);
circle(320-y*20,240-x*20,3);
circle(320+y*20,240-x*20,3);
circle(320+x*20,240-y*20,3);
}
void MidBresenhamcircle(int r) /* 中点Bresenham算法画圆的程序 */
{
int x,y,d;
x=0;y=r;d=1-r; /* 计算初始值 */
while(x<y)
{ circlePoint(x,y); /* 绘制点(x,y)及其在八分圆中的另外7个对称点 */
if(d<0) d+=2*x+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|<=11");
printf("\n输入半径值 r:");
scanf("%d",&r);
printf("按任意键显示图形...");
getch();
cleardevice();
setbkcolor(BLACK);
for(i=20;i<=620;i+=20) /*使用双循环画点函数画出表格中的纵坐标*/
for(j=20;j<=460;j++)
putpixel(i,j,2);
for(j=20;j<=460;j+=20) &n欢迎光临学网,收藏本篇文章 [1] [2]
$False$
bsp; /*使用双循环画点函数画出表格中的横坐标*/
for(i=20;i<=620;i++)
putpixel(i,j,2);
outtextxy(320,245,"0"); /*原点坐标*/
outtextxy(320-5*20,245,"-5");circle(320-5*20,240,2); /*横坐标值*/
outtextxy(320+5*20,245,"5");circle(320+5*20,240,2);
outtextxy(320-10*20,245,"-10");circle(320-10*20,240,2);
outtextxy(320+10*20,245,"10");circle(320+10*20,240,2);
outtextxy(320-15*20,245,"-15");circle(320-15*20,240,2);
outtextxy(320+15*20,245,"15");circle(320+15*20,240,2);
outtextxy(320,240-5*20,"-5");circle(320,240-5*20,2); /*纵坐标值*/
outtextxy(320,240+5*20,"5");circle(320,240+5*20,2);
outtextxy(320,240-10*20,"-10");circle(320,240-10*20,2);
outtextxy(320,240+10*20,"10");circle(320,240+10*20,2);
outtextxy(20,10,"The center of the circle is (0,0) "); /*坐标轴左上角显示提示信息*/
setcolor(RED); /*标记坐标轴*/
line(20,240,620,240); outtextxy(320+15*20,230,"X");
line(320,20,320,460); outtextxy(330,20,"Y");
setcolor(YELLOW);
MidBresenhamcircle(r);
setcolor(BLUE); /*绘制圆*/
circle(320,240,r*20);
setcolor(2);
getch();
closegraph();
}
#include <graphics.h> /*预定义库函数*/
void circlePoint(int x,int y) /*八分法画圆程序*/
{
circle(320+x*20,240+y*20,3);
circle(320+y*20,240+x*20,3);
circle(320-y*20,240+x*20,3);
circle(320-x*20,240+y*20,3);
circle(320-x*20,240+y*20,3);
circle(320-x*20,240-y*20,3);
circle(320-y*20,240-x*20,3);
circle(320+y*20,240-x*20,3);
circle(320+x*20,240-y*20,3);
}
void MidBresenhamcircle(int r) /* 中点Bresenham算法画圆的程序 */
{
int x,y,d;
x=0;y=r;d=1-r; /* 计算初始值 */
while(x<y)
{ circlePoint(x,y); /* 绘制点(x,y)及其在八分圆中的另外7个对称点 */
if(d<0) d+=2*x+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|<=11");
printf("\n输入半径值 r:");
scanf("%d",&r);
printf("按任意键显示图形...");
getch();
cleardevice();
setbkcolor(BLACK);
for(i=20;i<=620;i+=20) /*使用双循环画点函数画出表格中的纵坐标*/
for(j=20;j<=460;j++)
putpixel(i,j,2);
for(j=20;j<=460;j+=20) &n欢迎光临学网,收藏本篇文章 [1] [2]
$False$
bsp; /*使用双循环画点函数画出表格中的横坐标*/
for(i=20;i<=620;i++)
putpixel(i,j,2);
outtextxy(320,245,"0"); /*原点坐标*/
outtextxy(320-5*20,245,"-5");circle(320-5*20,240,2); /*横坐标值*/
outtextxy(320+5*20,245,"5");circle(320+5*20,240,2);
outtextxy(320-10*20,245,"-10");circle(320-10*20,240,2);
outtextxy(320+10*20,245,"10");circle(320+10*20,240,2);
outtextxy(320-15*20,245,"-15");circle(320-15*20,240,2);
outtextxy(320+15*20,245,"15");circle(320+15*20,240,2);
outtextxy(320,240-5*20,"-5");circle(320,240-5*20,2); /*纵坐标值*/
outtextxy(320,240+5*20,"5");circle(320,240+5*20,2);
outtextxy(320,240-10*20,"-10");circle(320,240-10*20,2);
outtextxy(320,240+10*20,"10");circle(320,240+10*20,2);
outtextxy(20,10,"The center of the circle is (0,0) "); /*坐标轴左上角显示提示信息*/
setcolor(RED); /*标记坐标轴*/
line(20,240,620,240); outtextxy(320+15*20,230,"X");
line(320,20,320,460); outtextxy(330,20,"Y");
setcolor(YELLOW);
MidBresenhamcircle(r);
setcolor(BLUE); /*绘制圆*/
circle(320,240,r*20);
setcolor(2);
getch();
closegraph();
}
展开全部
C语言画圆通过编译程序的方法即可。
程序源代码如下:
#include "stdio.h"
#include "graphics.h"
#include "conio.h"
main()
{
int driver=VGA,mode=VGAHI;
int i,num=15,top=50;
int left=20,right=50;
initgraph(&driver,&mode,"");
for(i=0;i<num;i++)
{
ellipse(250,250,0,360,right,left);
ellipse(250,250,0,360,20,top);
rectangle(20-2*i,20-2*i,10*(i+2),10*(i+2));
right+=5;
left+=5;
top+=10;
}
getch();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2008-02-15
展开全部
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
char arg[50]={0};
arg[0]= '\ " ';
strcpy(arg+1,argv[0]);
int len=int(strlen(arg));
arg[len]= '\ " ';
HWND hWnd=FindWindow(NULL,arg); //找到程序运行窗口的句柄
HDC hDC=GetDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄
HPEN hPen,hOldPen; //画笔
int i=0;
for(;i <500;++i)
SetPixel(hDC,10+i,10+i,0x0000ff);//用画点的办法画一根线,最后一个参数是颜色(32位)
hPen=CreatePen(PS_SOLID,2,0x00ff00);//生成绿色画笔
hOldPen=(HPEN)SelectObject(hDC,hPen);//把画笔引入设备场境
MoveToEx(hDC,20,50,NULL); //设置画线起点
LineTo(hDC,520,550); //画到终点
Arc(hDC,100,100,300,300,350,500,350,500);//画圆
SelectObject(hDC,hOldPen);
ReleaseDC(hWnd,hDC);
//下面是对比,表明它确实是控制台程序
printf( "hello console ");
system( "pause ");
return 0;
}
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char* argv[])
{
char arg[50]={0};
arg[0]= '\ " ';
strcpy(arg+1,argv[0]);
int len=int(strlen(arg));
arg[len]= '\ " ';
HWND hWnd=FindWindow(NULL,arg); //找到程序运行窗口的句柄
HDC hDC=GetDC(hWnd);//通过窗口句柄得到该窗口的设备场境句柄
HPEN hPen,hOldPen; //画笔
int i=0;
for(;i <500;++i)
SetPixel(hDC,10+i,10+i,0x0000ff);//用画点的办法画一根线,最后一个参数是颜色(32位)
hPen=CreatePen(PS_SOLID,2,0x00ff00);//生成绿色画笔
hOldPen=(HPEN)SelectObject(hDC,hPen);//把画笔引入设备场境
MoveToEx(hDC,20,50,NULL); //设置画线起点
LineTo(hDC,520,550); //画到终点
Arc(hDC,100,100,300,300,350,500,350,500);//画圆
SelectObject(hDC,hOldPen);
ReleaseDC(hWnd,hDC);
//下面是对比,表明它确实是控制台程序
printf( "hello console ");
system( "pause ");
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-21
展开全部
用搞这么罗嗦吗?晕,我这个精简点#include<stdio.h>
#include<math.h>
main()
{
double y;
int x,m;
for(y=10;y>=-10;y--)
{
m=2.5*sqrt(100-y*y);
for(x=1;x<50-m;x++)
printf(" ");
printf("*");
for(;x<50+m;x++)
printf(" ");
printf("*\n");
}
}
#include<math.h>
main()
{
double y;
int x,m;
for(y=10;y>=-10;y--)
{
m=2.5*sqrt(100-y*y);
for(x=1;x<50-m;x++)
printf(" ");
printf("*");
for(;x<50+m;x++)
printf(" ");
printf("*\n");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-21
展开全部
使用windows api创建一个窗口,然后调用Ellipse
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询