當前位置:編程學習大全網 - 編程語言 - C++畫圓(計算機圖形學)

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)?/*使用雙循環畫點函數畫出表格中的橫坐標*/

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();

}

  • 上一篇:啟源中學和文海實驗中學有什麽區別?
  • 下一篇:軟件開發方法論有哪些
  • copyright 2024編程學習大全網