物理情景模拟

作者在 2010-05-08 14:58:24 发布以下内容
#include<stdio.h>
#include<graphics.h>
#include<math.h>
#include<stdlib.h>
#include<dos.h>
#include<conio.h>
#include<time.h>
#define PI 3.1415926
void output_text()                         /*输出文本*/
  {
   outtextxy(120,200,"Dear friends:");
   outtextxy(120,215,"  Do you know ,everything in the space is harmonious");                   outtextxy(120,230,".We have no rights to break it  . On the contrary  ,");
   outtextxy(120,245,"it is our duty to protect it from being hurt. Don't.");
   outtextxy(120,260,"think that it's unfair,because we don'n have a justi");
   outtextxy(120,275,"-fication to refuse to protect our home.");
   outtextxy(450,295,"MR.REN");
   outtextxy(450,310,"14.3.2010");
   outtextxy(450,325,"GY.CHINA");
  }
void  draw_XOY()                           /*建立xoy坐标系*/
{
  setcolor(GREEN);
  setlinestyle(0,0,1);
  line(60,300,600,300);
  line(600,300,595,305);
  line(600,300,595,295);
  line(80,320,80,40);
  line(80,40,85,45);
  line(80,40,75,45);
 
  setcolor(LIGHTBLUE);
  outtextxy(70,305,"o");
  outtextxy(605,305,"X");
  outtextxy(60,40,"Y");
}
void output_text1(int angle,int v0)         /*输出文本*/
{  double spdx_str[10];
   double spdy_str[10];
   double Vx=v0*cos(angle);
   double Vy=v0*sin(angle);
  sprintf(spdx_str,"%.2lf",Vx);
  sprintf(spdy_str,"%.2lf",Vy);
  setcolor(WHITE);
  outtextxy(150,350,"*********************************************");
  outtextxy(150,365,"*  X&Y   SPEED      *       VALUE           *");
  outtextxy(150,380,"*********************************************");
  outtextxy(150,395,"*  Vx=Vo*cos<angle> *                       *");
  outtextxy(150,410,"*********************************************");
  outtextxy(150,425,"*  Vy=Vo*sin<angle> *                       *");
  outtextxy(150,440,"*********************************************");
  setcolor(WHITE);
  outtextxy(385,395,spdx_str);
  outtextxy(385,425,spdy_str);
  delay(100);
  setcolor(BLACK);
  outtextxy(385,395,spdx_str);
  outtextxy(385,425,spdy_str);
  
}
void drow_ball(int xbal,int ybal,int color,int x0,int y0)  /*画星球*/
{
  int seed=0;
  int ba=9;
  int bb=9;
  int bindex=0;
  setcolor(color==1?LIGHTBLUE:BLACK);
  for(bindex;bindex<=3;bindex++)
     {ellipse(xbal,ybal,0,360,ba,bb);
      bb-=3;
     }
  for(bindex=0;bindex<=3;bindex++)
     {ellipse(xbal,ybal,0,360,ba,bb);
      ba-=3;
     }
   seed=time(NULL);
   srand((unsigned int)seed);
   setcolor(color==1?rand()%16:BLACK);
   ellipse(xbal,ybal,-240,60,18,5);
   setcolor(color==1?YELLOW:BLACK);
   line(80,300,x0,y0);
   line(x0,y0,xbal,ybal);
   line(xbal,ybal,80,300);
}
void moving_ball()                           /*动态的星球*/
{ int x0=340;
  int y0=135;
  int x[361];
  int y[361];
  int a=170;
  int b=90;
  int index=0;
  int index1=0;
  int v0=100;
  double angle=2*PI/360;
  x[360]=x0+a;
  y[360]=y0;
  for(index;index<360;index++)
     {
       x[index]=x0+a*cos(index*angle);
       y[index]=y0+b*sin(index*angle);
     } 
  index=0;
  for(index1;index1<3;index1++)
  {  
     for(index;index<360;index++)
       { 
       
        drow_ball(x[index+1],y[index+1],1,x0,y0);
        angle*=index;
        output_text1(angle,v0);
        drow_ball(x[index],y[index],0,x0,y0);
        setcolor(YELLOW);
        ellipse(340,135,0,360,170,90);
        delay(100);
        angle=2*PI/360; 
       }
      index=0;
  }
     drow_ball(x[360],y[360],0,x0,y0);
     ellipse(340,135,0,360,170,90);
}
int main(void)
{
  int gdriver=VGA;
  int gmode=VGAHI;
  initgraph  (&gdriver,&gmode," ");
  output_text();
  getch();
  cleardevice();
  draw_XOY();
  getch();
  moving_ball();
  getch();
  cleardevice();
  setcolor(WHITE);
  settextstyle(0,0,8);
  outtextxy(200,200,"RENY");
  settextstyle(0,0,2);
  outtextxy(120,320,"E-mail:situjinxian@yahoo.cn");
  getch();
  closegraph();
  return 0;
}
在速度的显示上处理的不是很好,希望高手能指点一下。可以给我留言。
默认分类 | 阅读 665 次
文章评论,共0条
游客请输入验证码
文章分类
最新评论