绝想首页

精细绘图及动画

qhyqhyqhy [开心] 2008-08-09 17:20:59 星期六 晴天 查看:176 回复:1 发消息给作者

    精细绘图及动画
    
    上一篇: 灵活运用C语言实现高级功能
    下一篇: 使用ARGC,ARGC命令行参数的实例
    
    
    --------------------------------------------------------------------------------
    
    制个程序是本人自己编写,所以这里能后做出详细解释。程序运行后会在屏幕上用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 ",errormsg);
     printf("Press any key to exit. ");
     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

顶一下(34 写日记 34302 17292
最近访客
分享排行

 

 

留住已经逝去的峥嵘岁月 记住曾经绽现的万种风情 在记忆即将淡漠的时候 来把这些重新回味

Copyright (C) 2008-2014 www.juexiang.com, All Rights Reserved.

京ICP备2023001011号-3   京公网安备11010802011908号

客服QQ 1017160561 违法和不良信息举报电话 13148464312 邮箱 1017160561@qq.com