#include "graphics.h"
创新互联建站专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、网站制作、共青城网络推广、成都微信小程序、共青城网络营销、共青城企业策划、共青城品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联建站为所有大学生创业者提供共青城建站搭建服务,24小时服务热线:028-86922220,官方网址: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 /*预定义库函数*/
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; /* 根据误差项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 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(帧缓冲)。
帧的最低数量为24(人肉眼可见)(低于24则感觉到画面不流畅)。
显卡与帧的关系:由cpu调节其数据传输速率来输出其三基色的配比。
三基色:RGB(红绿蓝)。
在没有桌面和图形文件的系统界面,可以通过C语言的编程来实现在黑色背景上画图!
用下面的代码,在需要的地方(有注释)适当修改,就能画出自己喜欢的图形!
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();
}