在C语言中利用随机函数实现动画技术

Author: 江西 黄焕如 Date: 1993-08-06

        程序中改变X1、Y1、X2、Y2的数值,能将“微型机”图形移到屏幕的任何位置,改变XY的数值大小,能将“微型机”中屏幕范围放大或缩小。值得注意的是,该程序编译并链接成EXE文件后(TCC<文件名>GRAPHICS.LIB),在当前路径中必须含有EGA和VGA图形驱动程序及立体字符集(TRIP.CHR),否则程序会出错或者得不到放大的字体。如果将这些驱动程序和字符集事先链接在GRAPHICS.LIB中,然后再链接原程序,则该程序能脱离这些驱动程序和字符集而直接运行,具体操作可参考Turb C 2.0使用手册。
        本程序已在AST  386SX/20(VGA)上,Turb C 2.0编译下通过。
        /*利用随机函数实现动画技术实例*/
        #include<conioh>
        #include<stdioh>
        #include<stdibh>
        #include<graphicsh>
        #include<timeh>
        #defineX1260
        #defineY1140
        #defineX2320
        #defineY2180
        #defineXY16
        int  GDriver,GMode,MColors,ECode;
        struct  palettetype  palette;
        void  Initialize(void);void  RBars(void);
        int  main()
        {
        Initialize();/*初始化图形系统*//*显示放大字体*/
        setcolor(YELLOW);
        settextstyle(TRIPLEX-FONT,HORIZ-DIR,4);
        settextjustify(CENTER-TEXT,CENTER-TEXT);
        outtextxy((getmaxx()/2-17),360,"COMPUTER");
        RBars();/*主程序*/
        closegraph();/*关闭图形系统*/exit(1);
        }
        void  Initialize(void)
        {
        GDriver=DETECT;
        initgraph(&GDriver,&GMode,"");
        ECode=graphresult();
        if(ECode!=gr0k){
        printf("Graphics  Error:%s\n",grapherrormsg(ECode));
        exit(1);}
        getpalette(&palette);
        MColors=getmaxcolor()+1;
        }
        void  RBars(void)
        {
        int  color;/*画“微型计算机”图形*/
        setcolor(WHITE);
        setfillstyle(1,DARKGRAY);
        bar3d(X1-20,Y1-10,X2+56,Y2+70,0,3);
        setfillstyle(CLOSE-DOT-FILL,RED);
        bar(X1+4,Y1+78,X1+20,Y1+83);
        setcolor(MAGENTA);
        circle(X2+28,Y2+60,4);
        circle(X2+16,Y2+60,4);
        circle(X2+4,Y2+60,4);
        setcolor(WHITE);
        setfillstyle(SOLID-FILL,DARKGRAY);
        bar3d(X1-60,Y1+120,X1+154,Y1+170,0,2);
        bar3d(X1+20,Y1+126,X1+100,Y1+164,0,2);
        line(X1+20,Y1+145,X1+100,Y1+145);
        setfillstyle(SOLID-FILL,GREEN);
        bar(X1+26,Y1+130,X1+34,Y1+152);
        setfillstyle(WIDE-DOT-FILL,RED);
        bar(x1-24,y1+128,X1-44,Y1+142);
        /*利用随机函实现矩形画面互相覆盖,产生动感*/
        while(!dbhit()){
        color=random(MColors-1)+1;
        setcolor(color);
        setfillstyle(random(11)+1,color);
        bar3d(X1+random(getmaxx()/XY),Y1+random
        (getmaxy()/XY),
        X@+random(getmaxx()/XY),Y2+random
        (getmaxy()/XY),0,5);}
        }