#include "graphics.h"
創(chuàng)新互聯(lián)建站專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都網(wǎng)站建設(shè)、網(wǎng)站制作、共青城網(wǎng)絡(luò)推廣、成都微信小程序、共青城網(wǎng)絡(luò)營銷、共青城企業(yè)策劃、共青城品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們最大的嘉獎;創(chuàng)新互聯(lián)建站為所有大學生創(chuàng)業(yè)者提供共青城建站搭建服務(wù),24小時服務(wù)熱線:028-86922220,官方網(wǎng)址:www.cdcxhl.com
#include conio.h
void main() //畫圓
{
int driver,mode;
driver=VGA;mode=VGAHI;
initgraph(driver,mode,"");
setcolor(getmaxcolor());
circle(30,30,20);
getch();
closegraph();
}
給你個畫圓的例子
你參考一下
#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());
/* draw the circle */
circle(midx, midy, radius);
/* clean up */
getch();
closegraph();
return 0;
}
#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();
}
#include math.h#include stdio.h#define R 10 ? ?//半徑 #define X 10 ? ?//圓心x坐標 #define Y 10 ? ?//圓心Y坐標 int main(void)
{ ? ?int x,y; ? ?int m; ? ?int i; ? ?for(i=Y-R;i=1;i--)
{ ? ? ? ?printf("\n");
}
for(y=R;y=-R;y--)
{
? ?m=2*sqrt(R*R - y*y); ? ?//橫坐標的偏移量,因為字體長寬比例為2,所以要乘2
? ?for(x=1;xX+R-m;x++) ? ? ? ?//打印左半圓
? ?{ ? ? ? ? ? ?printf(" "); ? ?
? ?} ? ? ? ?printf("*"); ? ? ? ?for(;xX+R+m;x++) ? ? ? ? ? //打印右半圓
? ?{ ? ? ? ? ? ?printf(" ");
? ?} ? ? ? ?printf("*\n");
}
}
framebuffer(幀緩沖)。
幀的最低數(shù)量為24(人肉眼可見)(低于24則感覺到畫面不流暢)。
顯卡與幀的關(guān)系:由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");
#include graphics.h
#include stdio.h
#include math.h
#define TWOPI (3.1415926*2)
typedef struct point
{
int x;
int y;
}POINT;
void main()
{
int gd,gm;
POINT arr[1000];
int i;
int redius=80;
gd=DETECT;
initgraph(gd,gm,"C:\\JMSOFT\\DRV");
for(i=0;i1000;i++)
{
arr[i].x=300+redius*sin(((1.0*i)/1000)*TWOPI);
arr[i].y=300+redius*cos(((1.0*i)/1000)*TWOPI);;
}
for(i=0;i999;i++)
line(arr[i].x,arr[i].y,arr[i+1].x,arr[i+1].y);
getch();
closegraph();
}