以下三个都是很简单的C语言图形学的小程序,可以输出几个不错的图形,作为子函数还可以的,拿出来展览一下,不过运行的时候注意一下initgraph的路径,自己改一下吧。
#include<graphics.h> /*A simplest C graph product,run it directly*/
main()
{int x,driver=DETECT,mode;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
cleardevice();
setbkcolor(9);
for(x=170;x<=470;x=x+30)
{line(170,200,x,100);
line(170,200,x,300);
line(470,200,x,100);
line(470,200,x,300);
}
getch();
closegraph();
}
----------------------------------------------------------------------
#include<graphics.h> /*Input a number less than 50 and than Enter*/
#include<conio.h>
#include<math.h>
#define pi 3.1415926
#define max 50
main()
{int i,j,n,driver=DETECT,mode;
double r=100.0,theta,x[max],y[max];
printf("n(<=50)=");
scanf("%d",&n);
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
theta=2*pi/n;
for(i=0;i<n;i++)
{x[i]=320.0+2*r*cos(theta*i);
y[i]=200.0-r*sin(theta*i);
}
for(i=0;i<n-1;i++)
{for(j=i+1;j<n;j++)
{line((int)x[i],(int)y[i],(int)x[j],(int)y[j]);
}
}
getch();
closegraph();
}
-----------------------------------------------------------------------------
#include<graphics.h> /*A solid circle filled with 15 colors*/
main()
{int driver=DETECT,mode,i;
int start=0,end=24;
registerbgidriver(EGAVGA_driver);
initgraph(&driver,&mode,"");
for(i=0;i<15;i++)
{setfillstyle(1,i+1);
pieslice(320,200,start,end,100);
start=start+24;
end=end+24;
}
getch();
closegraph();
}
评论