用c语言设计简单动画的程序,CÓïÑÔ¾«Ï¸»æͼ¼°¶¯»­

ÖƸö³ÌÐòÊDZ¾ÈË×Ô¼º±àд£¬ËùÒÔÕâÀïÄܺó×ö³ö¾ßÌå½âÊÍ¡£³ÌÐòÔËÐкó»áÔÚÆÁÄ»ÉÏÓÃtriplex_fontÏÔʾ¡°press any key for set off¡±£¬ÏÂ

·½ÊÇÓûù±¾µÄÏßÌõ»­³öµÄ·¢Éä¼Ü£¨Óеã´Ö²Ú£©£¬¼´³ÌÐòÖеÄDrawGun()º¯Êý£¬µ±°´ÏÂÈÎÒâ¼üºó£¬½«ÔÚ·¢Éä¼ÜÉÏ·½³öÏÖÒ»¸öÓúáÏßÌî³äµÄ·É»ú£¬Í¬

ʱ±³¾°±»·±ÐÇÌî³ä£¬´Ëʱ±ØÐ밴סÈÎÒâ¼ü²»·Å£¬·ñÔò·É»ú½«²»»á·¢Éä¡£·¢ÉäÍê³Éºó£¬¼´·É»ú×ø±êСÓÚ0£¬½«³öÏÖÒ»¾ä»°£º"successfully!!!,press ESC to quit",ÈôÖÐ;°´ESCÍ˳ö£¬Ôò·É»úY×ø±ê²»Ð¡ÓÚ0£¬½«³öÏÖ"failue,..."Õâ¾ä»°¡£

#include

#include

#include

#include

#include

#define ESC 0x1b/*ESCµÄASCIIÂ룬ʮÁù½øÖÆ*/

void InstallGraph(void);/*ͼÐγÌÐò¼ÓÔغ¯ÊýµÄ˵ÃûÓï¾ä*/

void DrawGun(void); /*»­·¢Éä¼Üº¯ÊýµÄ˵Ã÷Óï¾ä*/

void DrawPlan(void); /*»­·É»úº¯ÊýµÄ˵Ã÷Óï¾ä*/

void DrawStar(void); /*»­ÐǺ¯ÊýµÄ˵Ã÷Óï¾ä*/

void *buf; /*È«¾Ö±äÁ¿£¬ÓÃÓÚ´æ´¢·É»úµÄͼÏñ*/

int x0=300; /*ÒÔÏÂÊÇ·É»úµÄλÖóõʼ»¯²ÎÊý*/

int y0=340;

int width1=5;

int width2=20;

int height=25;

int y1=8;

int y2=15;

int y3=23;

int y4=38;

/*Ö÷º¯Êý¿ªÊ¼*/

main()

{

int size;

int i=0;

int key;

int station;

InstallGraph();

setbkcolor(BLACK);

cleardevice();/*ͼÐÎÇý¶¯³ÌÐòºÍÆÁÄ»³õʼ»¯¹¤×÷Íê³É*/

setcolor(BLUE);/*ÉèÖÃ×ÖµÄÑÕÉ«*/

settextstyle(TRIPLEX_FONT,0,4);/*ÉèÖÃ×ÖÌå*/

outtextxy(80,100,"Ready!...Any key to SET OFF !!!");

DrawGun(); /*»­³ö·¢Éä¼Ü*/

getch(); /*if press key,clear the words and start*/

cleardevice();

DrawGun();

DrawPlan();

DrawStar();

setcolor(LIGHTRED);/*define result words color*/

¡¡¡¡do{ /*³ÌÐòÖ÷Ñ­»·¿ªÊ¼£¬ÓÃÓÚÔ˶¯·É»ú£¬·½·¨ÊÇÓÃÒì»òµÄ·½Ê½ÔÚÆÁÄ»ÉÏÁ¬Ðø»­³ö·É»ú µÄͼÏñ£¬Ã¿»­Ò»´Î£¬ÐÂͼÏñºÍÀ´µÄλÖÃÏà²îÁ½¸öÏñËص㡣

Õâ¸öÖµÊǿɵ÷µÄ£¬ÖµÔ½´ó£¬·É»ú·ÉÐеÄËÙ¶ÈÔ½¿ì*/

putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);

i+=2;

putimage(x0-width2,y0-height-3*width1-i,buf,XOR_PUT);

key=getch();

if(y0-height-3*width1-i==0)

outtextxy(60,100,"Successfully!!! Press ESC to quit");

if(key==ESC){

if(y0-height-3*width1-i>0){

cleardevice();

outtextxy(100,100,"Failue. What did you do?");

outtextxy(130,300,"Press any key to quit.");

getch();

}

}

}while(key!=ESC);

free(buf);

closegraph();

return 0;

}

/*****************Install the graphics library***********************/

void InstallGraph(void)

{

int grdriver=DETECT;

int grmode;

int errorcode;

char *errormsg;

registerbgidriver(EGAVGA_driver);

registerbgifont(triplex_font);

initgraph(&grdriver,&grmode,"");

errorcode=graphresult();

errormsg=grapherrormsg(errorcode);

if(errorcode!=grOk){

printf("Graphics error: %s\n",errormsg);

printf("Press any key to exit.\n");

getch();

exit(1);

}

}

/************************Draw the star ********************************/

void DrawStar(void)

{

int seed=2000;

int i,dotx,doty,height,width,color,maxcolor;

maxcolor=getmaxcolor();

width=getmaxx();

height=getmaxy();

srand(seed);

for(i=0;i<250;i++){

dotx=i+random(width-1);

doty=i+random(height-1);

color=random(maxcolor);

setcolor(color);

putpixel(dotx,doty,color);

circle(dotx+1,doty+1,1);

}

srand(seed);

}

/****************Draw the bottom gun********************/

void DrawGun(void)

{

int x0=300;

int y0=430;

int height=45;

int rx=20;

int ry=5;

int rightx,righty,leftx,lefty;

int centery1=30;

rightx=righty=leftx=lefty=12;

setcolor(LIGHTGREEN);

ellipse(x0,y0,180,360,rx,ry);

ellipse(x0,y0-height,0,360,rx,ry);

line(x0+rx,y0,x0+rx,y0-height);

line(x0-rx,y0,x0-rx,y0-height);

moveto(x0+rx,y0);

lineto(x0+rx+rightx,y0+righty);

moveto(x0+rx+rightx,y0+righty);

lineto(x0+rx+rightx+10,y0+righty+10);

circle(x0+rx+rightx+10,y0+righty+10,4);

moveto(x0,y0+ry);

lineto(x0,y0+centery1);

moveto(x0,y0+centery1);

lineto(x0,y0+centery1+10);

circle(x0,y0+centery1+10,4);

moveto(x0-rx,y0);

lineto(x0-rx-leftx,y0+lefty);

moveto(x0-rx-leftx,y0+lefty);

lineto(x0-rx-leftx-10,y0+lefty+10);

circle(x0-rx-leftx-10,y0+lefty+10,4);

line(x0-rx-leftx,y0+lefty,x0,y0+centery1);

line(x0,y0+centery1,x0+rx+rightx,y0+righty);

}

/*****************Draw the plan fly to the sky***********************/

void DrawPlan(void)

{

int size;

setcolor(LIGHTRED);

setfillstyle(1,BLUE);

ellipse(x0,y0-height,0,180,width1,3*width1);

moveto(x0+width1,y0); /*moveto center right side*/

lineto(x0+width1,y0-height);

moveto(x0+width1,y0);

lineto(x0+width2,y0+y2);

moveto(x0-width1,y0); /*moveto center left side*/

lineto(x0-width1,y0-height);

moveto(x0-width1,y0);

lineto(x0-width2,y0+y2);

moveto(x0+width2,y0+y3);/*moveto right bottom side*/

lineto(x0+width2,y0+y1);

moveto(x0+width2,y0+y3);

lineto(x0+width1,y0+y2);

moveto(x0-width2,y0+y3);/*moveto left bottom side*/

lineto(x0-width2,y0+y1);

moveto(x0-width2,y0+y3);

lineto(x0-width1,y0+y2);

moveto(x0,y0+y4); /*moveto the bottomest*/

lineto(x0+width1,y0+y2);

moveto(x0,y0+y4);

lineto(x0-width1,y0+y2);

setfillstyle(2,LIGHTRED); /*fill the plan with a style */

floodfill(x0,y0,LIGHTRED);

size=imagesize(x0-width2-1,y0-height-3*width1,

x0+width2+1,y0+y4);

buf=malloc(size);

if(!buf){

printf("No enough memory!");

exit(0);

}

getimage(x0-width2,y0-height-3*width1,x0+width2,y0+y4,buf);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值