用graphics函式
坦克圖畫:
#include"graphics.h"
#include"conio.h"
void Tanke(int x,int y,int R,int TColor,int FColor)
{
int i,j,d,t;
d=R/4;t=d*0.6;
setcolor(TColor);
/*--------------------------------------------*/
line(x-R,y,x+R-t,y);
line(x-R,y,x-R+d,y+2*d);
line(x-R+d,y+2*d,x+3*d,y+2*d);
line(x+3*d,y+2*d,x+R-t,y);
line(x-R,y,x-R+t,y-t);
line(x-R+t,y-t,x-2*d,y-t);
line(x-2*d,y-t,x-2*d+t,y-d-t);
line(x-2*d+t,y-d-t,x-3*d,y-d-t);
line(x-3*d,y-d-t,x-3*d+t,y-2*d);
line(x-3*d+t,y-2*d,x+R-t,y-2*d);
line(x+R-t,y-2*d,x+R-t,y);
/*-------------------------------------------*/
line(x-3*d,y-d-t,x-2*d,y-t);
line(x-R+d-t,y+2*(d-t),x+3*d+R*0.04,y+2*(d-t));
for(i=0;i<2*(R/d-1);i++)
line(x-3*d+i*d,y+2*(d-t),x-3*d+i*d,y+2*d);
setfillstyle(1,TColor);
bar(x-d*1.2,y-d*0.6,x+d*2,y-d*0.2);
line(x-d*1.2,y-d*0.6,x-d*0.6,y-d*1.8);
line(x-d*0.6,y-d*1.8,x+d*2.4,y-d*1.8);
line(x+d*2.4,y-d*1.8,x+d*2,y-d*0.6);
line(x+d*2.4,y-d*1.8,x+d*2.4,y-d*1.4);
line(x+d*2,y-d*0.2,x+d*2.4,y-d*1.4);
sector(x+d*0.6,y-d,0,180,d*1.2,d*1.4);
for(i=0;i<d*0.3;i++) /*畫炮杆*/
line(x+d*0.2,y-d*1.8+i,x-d*2.5,y-d*1.8+i);
setfillstyle(1,FColor);
bar(x-d*3,y-d*1.9,x-d*2.3,y-d*1.3); /*炮頭(紅色)*/
}
main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
setcolor(0);
Tanke(300,200,50,WHITE,RED);
getch();
closegraph();
如果想用C語言畫特殊圖形學學WIN32 GUI程式設計吧,用GDI或GDI+或是使用其它類庫也行,用控制檯程式畫特殊圖形有點不太方便
用graphics函式
坦克圖畫:
#include"graphics.h"
#include"conio.h"
void Tanke(int x,int y,int R,int TColor,int FColor)
{
int i,j,d,t;
d=R/4;t=d*0.6;
setcolor(TColor);
/*--------------------------------------------*/
line(x-R,y,x+R-t,y);
line(x-R,y,x-R+d,y+2*d);
line(x-R+d,y+2*d,x+3*d,y+2*d);
line(x+3*d,y+2*d,x+R-t,y);
/*--------------------------------------------*/
line(x-R,y,x-R+t,y-t);
line(x-R+t,y-t,x-2*d,y-t);
line(x-2*d,y-t,x-2*d+t,y-d-t);
line(x-2*d+t,y-d-t,x-3*d,y-d-t);
line(x-3*d,y-d-t,x-3*d+t,y-2*d);
line(x-3*d+t,y-2*d,x+R-t,y-2*d);
line(x+R-t,y-2*d,x+R-t,y);
/*-------------------------------------------*/
line(x-3*d,y-d-t,x-2*d,y-t);
/*-------------------------------------------*/
line(x-R+d-t,y+2*(d-t),x+3*d+R*0.04,y+2*(d-t));
for(i=0;i<2*(R/d-1);i++)
line(x-3*d+i*d,y+2*(d-t),x-3*d+i*d,y+2*d);
/*-------------------------------------------*/
setfillstyle(1,TColor);
bar(x-d*1.2,y-d*0.6,x+d*2,y-d*0.2);
line(x-d*1.2,y-d*0.6,x-d*0.6,y-d*1.8);
line(x-d*0.6,y-d*1.8,x+d*2.4,y-d*1.8);
line(x+d*2.4,y-d*1.8,x+d*2,y-d*0.6);
line(x+d*2.4,y-d*1.8,x+d*2.4,y-d*1.4);
line(x+d*2,y-d*0.2,x+d*2.4,y-d*1.4);
/*-------------------------------------------*/
sector(x+d*0.6,y-d,0,180,d*1.2,d*1.4);
/*-------------------------------------------*/
for(i=0;i<d*0.3;i++) /*畫炮杆*/
line(x+d*0.2,y-d*1.8+i,x-d*2.5,y-d*1.8+i);
setfillstyle(1,FColor);
bar(x-d*3,y-d*1.9,x-d*2.3,y-d*1.3); /*炮頭(紅色)*/
}
main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
setcolor(0);
Tanke(300,200,50,WHITE,RED);
getch();
closegraph();
}