A. 用C語言寫出畫一個圓形的代碼
可以參考下面的代碼:
#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("* ");
}
}
(1)c編程如何畫四個並列的圓擴展閱讀:
for循表達式為:for(單次表達式;條件表達式;末尾循環體)版{中間循環體;權}。
其中,表示式皆可以省略,但分號不可省略,因為「;」可以代表一個空語句,省略了之後語句減少,即為語句格式發生變化,則編譯器不能識別而無法進行編譯。for循環小括弧里第一個「;」號前為一個為不參與循環的單次表達式。
B. 怎樣用C語言畫圓
#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();
}
C. c語言的畫圓代碼
假設圓心點是(x0,y0),半徑是r
for(x=x0-r;x<=x0+r;x+=o.1)
for(y=y0-r;x<=y0+r;y+=o.1)
line(x,y,x0,y0);