谁有c语言动画程序的源码吗?
   要求二维画面就行,
   程序最好在100行左右,
   主要是为了应付老师(由于要考研实在没时间啊!)
 谢谢!!!

解决方案 »

  1.   

    #include <math.h>
    #include <stdio.h>
    #include <graphics.h>
    #include <dos.h>#define pi 3.1415926535double  ca3mm1(double m1,double m2);
    double  ca3fm1(double cosine,double sine);
    double  ca5fm2(double a6m,double a5m,double a4m,double a4f,int shang);
    double  ca6fm2(double a4m ,double a4f,double a5m , double a5f);
    char inbox(int x,int y,int x1,int y1);
    char buf();  main()
        {
    double m=3.0;
    double xo=100.0,yo=200.0,a1=30.0,t1=pi;
    double xc=xo+m*a1,yc=yo;
    double a2=8.0,a3,a4=25.0,a5=30.0,a6=20.0,a7=35.0;
    double t2,t3,t4,t5,t6,t7;
    double xo1=xo+m*150,yo1=yo;
    double xc1=xo1-m*a1,yc1=yo1;
    double i,j,k;
    double l1;
    double n=116.1,nt;
    initscreen(); setfillstyle(SOLID_FILL,DARKGRAY);
    bar(0,0,640,480);
    mybutton(10,10,"BEGIN",1,0);
    mybutton(500,10,"EXIT",1,0);
    line(0,69,640,69);
    mouseinit();
    changemousecross();
    setmousexy(320,20);
    mouseshow();
    setmousearea(0,0,640,60);
    do{
    if(inbox(10,10,70,26)&&button()==1)
      {mousehide();
       mybutton(10,10,"BEGIN",0,0);
       mouseshow();
       mousehold();
       mousehide();
       mybutton(10,10,"BEGIN",1,7);
       mouseshow();
       break;
      }
    if(inbox(500,10,555,26)&&button()==1)
      {mousehide();
       mybutton(500,10,"EXIT",0,0);
       mouseshow();
       mousehold();
       mousehide();
       mybutton(500,10,"EXIT",1,7);
       mouseshow();
       exit(0);
       }
    if(buf()==56)
      for(i=0;i<10000;i++){
       switch (buf()){
       case 18:{
                           mousehide();
       mybutton(500,10,"EXIT",0,0);
       mouseshow();
       delay(4000);
       mousehide();
       mybutton(500,10,"EXIT",1,7);
       mouseshow();
       exit(0);
       }
       case 48: {
       mousehide();
       mybutton(10,10,"BEGIN",0,0);
       mouseshow();
       delay(4000);
       mousehide();
       mybutton(10,10,"BEGIN",1,7);
       mouseshow();
       goto run;
       }
       default:break;
       }
      }
    }while(1);
    run:
    drawjijia(xo,yo,1);
    drawjijia(xc,yc,1);
    drawjijia(xo1,yo1,1);
    drawjijia(xc1,yc1,1);
    setwritemode(1);
    do{
       for(i=0;i<360.0;i+=1.0)
       {
    t2=i;
    a3=ca3mm1(a1*cos(t1)+a2*cos(t2*pi/180.0),a1*sin(t1)+a2*sin(t2*pi/180.0));
    t3=ca3fm1(a1*cos(t1)+a2*cos(t2*pi/180.0),a1*sin(t1)+a2*sin(t2*pi/180.0));
    a4=a3;
    t4=t3;
    t5=ca5fm2(a6,a5,a4,t4,0);
    t6=ca6fm2(a4,t4,a5,t5);
    t7=t6-90.0;
    l1=xc1-xc-2*m*a7*cos(t7*pi/180);
    nt=(asin(l1/2/(n/2))*180/pi)-90.0;
    drawline(xo,yo,a2,t2,m,LIGHTGRAY);
    drawline(xo+m*a2*cos(t2*pi/180),yo-m*a2*sin(t2*pi/180),a5,t5,m,LIGHTGRAY);
    drawline(xc,yc,a6,t6,m,LIGHTGRAY);
    drawline(xc,yc,a7,t7,m,LIGHTGRAY);
    drawline1(xo1,yo1,a2,t2,m,LIGHTGRAY);
    drawline1(xo1+m*a2*cos((180-t2)*pi/180),yo1-m*a2*sin((180-t2)*pi/180),a5,t5,m,LIGHTGRAY);
    drawline1(xc1,yc1,a6,t6,m,LIGHTGRAY);
    drawline1(xc1,yc1,a7,t7,m,LIGHTGRAY);
    for(j=-1;j<20;j++)
    {   drawline(xc+m*a7*cos(t7*pi/180),(yc-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,GREEN);
    drawline1(xc1-m*a7*cos(t7*pi/180),(yc1-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,DARKGRAY);
    }
    delay(300);
    drawline(xo,yo,a2,t2,m,LIGHTGRAY);
    drawline(xo+m*a2*cos(t2*pi/180.0),yo-m*a2*sin(t2*pi/180.0),a5,t5,m,LIGHTGRAY);
    drawline(xc,yc,a6,t6,m,LIGHTGRAY);
    drawline(xc,yc,a7,t7,m,LIGHTGRAY);
    drawline1(xo1,yo1,a2,t2,m,LIGHTGRAY);
    drawline1(xo1+m*a2*cos((180-t2)*pi/180),yo1-m*a2*sin((180-t2)*pi/180),a5,t5,m,LIGHTGRAY);
    drawline1(xc1,yc1,a6,t6,m,LIGHTGRAY);
    drawline1(xc1,yc1,a7,t7,m,LIGHTGRAY);
    for(j=-1;j<20;j++)
    {   drawline(xc+m*a7*cos(t7*pi/180),(yc-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,GREEN);
    drawline1(xc1-m*a7*cos(t7*pi/180),(yc1-m*a7*sin(t7*pi/180)-j*n*sin(nt*pi/180)),n,nt,1.0,DARKGRAY);
    }
    setwritemode(0);
    if(inbox(500,10,555,26)&&button()==1)
      {mousehide();
       mybutton(500,10,"EXIT",0,0);
       mouseshow();
       mousehold();
       mousehide();
       mybutton(500,10,"EXIT",1,7);
       mouseshow();
       exit(0);
      }
               if(buf()==56)
      for(k=0;k<10000;k++){
       switch (buf()){
       case 18:{
       mousehide();
       mybutton(500,10,"EXIT",0,0);
       mouseshow();
       delay(4000);
       mousehide();
       mybutton(500,10,"EXIT",1,7);
       mouseshow();
       exit(0); }
       default:break;
       }
      }
       setwritemode(1);
       }
    }while(1);
     } drawline(double xo,double yo,double mo,double fujiao,double m,int color)
     {
    double x,y;
    x=(xo+m*mo*cos(fujiao*pi/180));
    y=(yo-m*mo*sin(fujiao*pi/180));
    setcolor(color);
    line (xo,yo,x,y);
     }
     drawline1(double xo,double yo,double mo,double fujiao,double m,int color)
     {
          double x,y;
    x=(xo-m*mo*cos(fujiao*pi/180));
    y=(yo-m*mo*sin(fujiao*pi/180));
    setcolor(color);
    line (xo,yo,x,y);
     }
      drawjijia(double x,double y,int shang)
         {
       setcolor(RED);
       if (shang==1){
     circle(x,y,3);
     line(x-3.0,y+3.0,x-15.0,y+20.0);
     moveto(x-15,(int)(y+20));
     lineto((int)(x+15),(int)(y+20));
     moveto((int)(x+15),(int)(y+20));
     lineto(x+3,y+3);}
       setcolor(RED);
       if (shang==0){
     circle((int)x,(int)y,3);
     line (x-3,y-3,x-15,y-20);
     moveto(x-15,y-20);
     lineto(x+15,y-20);
     moveto(x+15,y-20);
     lineto(x+3,y-3);
     }
         }
      double ca3mm1(double m1,double m2)
     {
       double temp;
       temp = sqrt(m1*m1 + m2*m2);
       return(temp);
     }
      double ca3fm1(double cosine,double sine)
     {
       float temp;
       if (sine > 0 && cosine > 0)
      temp = atan(sine / cosine) * 180 / pi;
       if (sine > 0 && cosine < 0)
      temp = (atan(sine / cosine) + pi) * 180 / pi;
       if (sine < 0 && cosine < 0)
      temp = (atan(sine / cosine) + pi) * 180 / pi;
       if (sine < 0 && cosine > 0)
      temp = (atan(sine / cosine) + 2 * pi) * 180 / pi;
       return(temp);
     }
     double  ca5fm2(double a6m,double a5m,double a4m,double a4f,int shang)
     {
       double temp,sine1,cosine1;
       cosine1 = (a6m *a6m - a4m *a4m - a5m*a5m) / (2 * a4m * a5m);
       sine1 = sqrt(1 - cosine1 *cosine1);
       if (shang==0)
       sine1 = sine1*(-1);
       if (sine1 > 0 && cosine1 > 0)
       temp = a4f + (atan(sine1 / cosine1) * 180 / pi);
       if (sine1 > 0 && cosine1 < 0)
       temp = a4f + ((atan(sine1 / cosine1) + pi) * 180 / pi);
       if (sine1 < 0 && cosine1 < 0)
       temp = a4f + ((atan(sine1 / cosine1) + pi) * 180 / pi);
       if (sine1 < 0 && cosine1 > 0)
       temp = a4f + ((atan(sine1 / cosine1) + 2 * pi) * 180 / pi);
    return(temp);
     }
     double  ca6fm2(double a4m ,double a4f,double a5m , double a5f)
     {
       double temp,sine1,cosine1;
       sine1 = a4m * sin(a4f * pi / 180) + a5m * sin(a5f * pi / 180);
       cosine1 = a4m * cos(a4f * pi / 180) + a5m * cos(a5f * pi / 180);    if (sine1 > 0 && cosine1 > 0)
       temp = (atan(sine1 / cosine1) * 180 / pi);
       if (sine1 > 0 && cosine1 < 0)
       temp = ((atan(sine1 / cosine1) + pi) * 180 / pi);
       if (sine1 < 0 && cosine1 < 0)
       temp = ((atan(sine1 / cosine1) + pi) * 180 / pi);
       if (sine1 < 0 && cosine1 > 0)
       temp = ((atan(sine1 / cosine1) + 2 * pi) * 180 / pi);
    return(temp);
     }
    initscreen()
    {
      int gd=DETECT,gm;
      registerbgidriver(EGAVGA_driver);
      initgraph(&gd,&gm,"");
    }
      

  2.   

    mybutton(int x,int y,char string[],int pop,int color)
      {
     int x1,y1;
     x1=x+textwidth(string)+20;
     y1=y+textheight(string)+10;;
     if(pop)
     {      setcolor(LIGHTGRAY);
    line(x,y,x,y1);
    line(x,y,x1,y);
    setcolor(BLACK);
    line(x,y1,x1,y1);
    line(x1,y,x1,y1);
    setcolor(color);
    outtextxy(x+10,y+5,string);
    line(x+10,y+14,x+16,y+14);
     }
    else{
    setcolor(BLACK);
    line(x,y,x,y1);
    line(x,y,x1,y);
    setcolor(LIGHTGRAY);
    line(x,y1,x1,y1);
    line(x1,y,x1,y1);
    setcolor(color);
    outtextxy(x+10,y+5,string);
                        line(x+10,y+14,x+16,y+14);
     }
      }
    char inbox(int x,int y,int x1,int y1)
     {
      if(mousex()>x&&mousex()<x1&&mousey()>y&&mousey()<y1)
    return(1);
      else
    return(0);
     }
    changemousecross()
    {
      union REGS r;
      struct SREGS s;
      unsigned xie[32];
      xie[0]= 0x1FF8;
      xie[1] = 0x0FF0;
      xie[2] = 0x07E0;
      xie[3] = 0x83C1;
      xie[4] = 0xC183;
      xie[5] = 0xE007;
      xie[6] = 0xF00F;
      xie[7] = 0xF81F;
      xie[8] = 0xF81F;
      xie[9] = 0xF00F;
      xie[10] = 0xE007;
      xie[11] = 0xC183;
      xie[12] = 0x83C1;
      xie[13] = 0x07E0;
      xie[14] = 0x0FF0;
      xie[15] = 0x1FF8;
      xie[16]= 0xe007;
      xie[17] = 0x9009;
      xie[18] = 0x8811;
      xie[19] = 0x4422;
      xie[20] = 0x2244;
      xie[21] = 0x1188;
      xie[22] = 0x0810;
      xie[23] = 0x0420;
      xie[24] = 0x0420;
      xie[25] = 0x0810;
      xie[26] = 0x1188;
      xie[27] = 0x2244;
      xie[28] = 0x4422;
      xie[29] = 0x8811;
      xie[30] = 0x9009;
      xie[31] = 0xe007;
      r.x.ax=9;
      r.x.bx=7;
      r.x.cx=7;
      r.x.dx=FP_OFF(xie);
      s.es=FP_SEG(xie);
      int86x(0x33,&r,&r,&s);
      }
    mouseinit()
    {
     union REGS r;
     r.x.ax=0;
     int86(0x33,&r,&r);
     if(r.x.ax==NULL){
       printf("Mouse not found,Please run Mouse.Com first!!\n");
       exit(0);
       }
    }
    mouseshow()
    {
       union REGS r;
       r.x.ax=1;
       int86(0x33,&r,&r);
    }
    mousehide()
    {
       union REGS r;
       r.x.ax=2;
       int86(0x33,&r,&r);
    }
    mousex()
      {
    union REGS r;
    int temp;
    r.x.ax=3;
    int86(0x33,&r,&r);
    temp=r.x.cx;
    return(temp);
      }
    mousey()
      {
    union REGS r;
    int temp;
    r.x.ax=3;
    int86(0x33,&r,&r);
    temp=r.x.dx;
    return(temp);
      }
    button()
      {
    union REGS r;
    int temp;
    r.x.ax=3;
    int86(0x33,&r,&r);
    temp=r.x.bx;
    return(temp);
      }
    mousehold()
     {
       do{
      }while(button()==1);
       }
    char buf()
    {
      return(inportb(0x60));
    }
    setmousexy(int x,int y)
       {
     union REGS r;
     r.x.cx=x;
     r.x.dx=y;
     r.x.ax=4;
     int86(0x33,&r,&r);
       }
    setmousearea(int x,int y,int x1,int y1)
       {
     union REGS r;
     r.x.cx=x;
     r.x.dx=x1;
     r.x.ax=7;
     int86(0x33,&r,&r);
     r.x.cx=y;
     r.x.dx=y1;
     r.x.ax=8;
     int86(0x33,&r,&r);
       }
    setmousehidearea(int x,int y,int x1,int y1)
      {
    union REGS r;
    r.x.cx=x;
    r.x.dx=y;
    r.x.si=x1;
    r.x.di=y1;
    r.x.ax=0x10;
    int86(0x33,&r,&r);
      }
      

  3.   

    #include "graphics.h"
    #define  LEFT 0
    #define  TOP 0
    #define  RIGHT 639
    #define  BOTTOM 479
    #define  LINES 400
    #define  MAXCOLOR 15
    main()
    {
        int driver,mode;
        int x1,y1,x2,y2,dx1,dy1,dx2,dy2;
        int count=0,color=0;    driver=VGA;
        mode=VGAHI;
        initgraph(&driver,&mode,"");
        x1=x2=y1=y2=10;
        dx1=dy1=2;
        dx2=dy2=3;
        while (!kbhit())
        {
             line(x1,y1,x2,y2);
             x1+=dx1;y1+=dy1;
             x2+=dx2;y2+=dy2;
     if (x1<=LEFT || x1>=RIGHT)
                dx1=-dx1;
             if (y1<=TOP || y1>=BOTTOM)
                dy1=-dy1;
             if (x2<=LEFT || x2>=RIGHT)
                dx2=-dx2;
             if (y2<=TOP || y2>=BOTTOM)
                 dy2=-dy2;
             if (++count>LINES)
                {
                    setcolor(color);
    color=(color>=MAXCOLOR)?0:++color;
                    count=0;
                 }
        }
        closegraph();
    }