c語言標準庫畫圓函數(shù) c語言畫圓形

C語言如何畫圖

framebuffer(幀緩沖)。

站在用戶的角度思考問題,與客戶深入溝通,找到南山網(wǎng)站設計與南山網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設計與互聯(lián)網(wǎng)技術結合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站設計、網(wǎng)站建設、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊、網(wǎng)絡空間、企業(yè)郵箱。業(yè)務覆蓋南山地區(qū)。

幀的最低數(shù)量為24(人肉眼可見)(低于24則感覺到畫面不流暢)。

顯卡與幀的關系:由cpu調(diào)節(jié)其數(shù)據(jù)傳輸速率來輸出其三基色的配比。

三基色:RGB(紅綠藍)。

在沒有桌面和圖形文件的系統(tǒng)界面,可以通過C語言的編程來實現(xiàn)在黑色背景上畫圖!

用下面的代碼,在需要的地方(有注釋)適當修改,就能畫出自己喜歡的圖形!

PS:同樣要編譯運行后才能出效果。

#include stdio.h

#include sys/mman.h

#include fcntl.h

#include linux/fb.h

#include stdlib.h

#define RGB888(r,g,b) ((r 0xff) 16 | (g 0xff) 8 | (b 0xff))

#define RGB565(r,g,b) ((r 0x1f) 11 | (g 0x3f) 5 | (b 0x1f))

int main()

{

int fd = open("/dev/fb0", O_RDWR);

if(fd 0){

perror("open err. \n");

exit(EXIT_FAILURE);

printf("xres: %d\n", info.xres);

printf("yres: %d\n", info.yres);

printf("bits_per_pixel: %d\n", info.bits_per_pixel);

size_t len = info.xres*info.yres*info.bits_per_pixel 3;

unsigned long* addr = NULL;

addr = mmap(NULL, len, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0);

if(addr == (void*)-1){

perror("mmap err. \n");

怎樣用C語言畫圓?

#include math.h

#include graphics.h /*預定義庫函數(shù)*/

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

{ circlePoint(x,y); /* 繪制點(x,y)及其在八分圓中的另外7個對稱點 */

if(d0) d+=2*x+3; /* 根據(jù)誤差項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) /*使用雙循環(huán)畫點函數(shù)畫出表格中的縱坐標*/

for(j=20;j=460;j++)

putpixel(i,j,2);

for(j=20;j=460;j+=20) n歡迎光臨學網(wǎng),收藏本篇文章 [1] [2]

$False$

bsp; /*使用雙循環(huán)畫點函數(shù)畫出表格中的橫坐標*/

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語言畫出一個隨時間變化的圓形

circle函數(shù)是TURBO C提供的圖形接口,用來畫圓。不屬于標準庫函數(shù),不具備可移植性。

函數(shù)名:circle

功 能: 在給定半徑以(x, y)為圓心畫圓

用 法:void far circle(int x, int y, int radius)

隨時間變化,可以用cleardevice函數(shù)清除屏幕,不斷畫半徑不同的圓。看起來就像是一個隨時間變化的圓形。

函數(shù)名: cleardevice

功 能: 清除圖形屏幕

用 法: void far cleardevice(void);

例程:

#include?graphics.h

#include?stdlib.h

#include?stdio.h

#include?conio.h

int?main(void)

{

/*?request?auto?detection?*/

int?gdriver?=?DETECT,?gmode,?errorcode;

int?midx,?midy;

int?radius?=?100;

/*?initialize?graphics?and?local?variables?*/

initgraph(gdriver,?gmode,?"");

/*?read?result?of?initialization?*/

errorcode?=?graphresult();

if?(errorcode?!=?grOk)?/*?an?error?occurred?*/

{

printf("Graphics?error:?%s\n",?grapherrormsg(errorcode));

printf("Press?any?key?to?halt:");

getch();

exit(1);?/*?terminate?with?an?error?code?*/

}

midx?=?getmaxx()?/?2;

midy?=?getmaxy()?/?2;

setcolor(getmaxcolor());

for(i=0;i1000000;i++)?if(i%50000==0){

cleardevice();/*?clean?the?screen?*/

circle(midx,?midy,?radius--);/*?draw?the?circle?*/

}

getch();

closegraph();

return?0;

}

網(wǎng)站名稱:c語言標準庫畫圓函數(shù) c語言畫圓形
鏈接分享:http://muchs.cn/article14/doshoge.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信公眾號、面包屑導航、網(wǎng)頁設計公司、網(wǎng)站改版、微信小程序網(wǎng)站制作

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設網(wǎng)站維護公司