Пример #1
0
Файл: fold.c Проект: aiju/hdl
static int
constfmt(Fmt *f)
{
	Const *c;
	int rc;
	int s;
	
	c = va_arg(f->args, Const *);
	rc = 0;
	if(c == nil || c->n == nil || c->x == nil)
		return fmtstrcpy(f, "<nil>");
	s = c->n->sign;
	if(s < 0){
		c->n->sign = 1;
		rc += fmtrune(f, '-');
	}
	if(c->sz != 0)
		rc += fmtprint(f, "%d", c->sz);
	if(!is0(c->x)){
		rc += binput(f, c);
	}else if(c->base == 0 || c->base == 10)
		rc += fmtprint(f, c->sz != 0 ? "'d%.10B" : "%.10B", c->n);
	else if(c->base == 16)
		rc += fmtprint(f, "'h%.16B", c->n);
	else
		rc += fmtprint(f, "'b%.2B", c->n);
	c->n->sign = s;
	return rc;
}
Пример #2
0
 void handle(event mev)
 {int f=0;
  me[2]=me[1];
  me[1]=mev;
  if(is1(sc.flag,15))
  {if(me[1].key==1)endprogram();
   else status("Press any key to exit");

  }
  if(me[1].key==1&&me[1].ch==27)
  {set0(sc.flag,0);
   set0(sc.flag,1);
   set1(sc.flag,15);
   status("Press any key to exit");
  }
  t1.handle(me);
  t2.handle(me);
  t3.handle(me);
  sc.handle(me);
  e1.handle(me);
  e2.handle(me);
  e3.handle(me);e3.st[0]=0;
  e4.handle(me);e4.st[0]=0;
  e5.handle(me);e5.st[0]=0;
  e6.handle(me);e6.st[0]=0;
  b.handle(me);
  rb1.handle(me);
  rb2.handle(me);
  scrbar.handle(me);
  if(is1(sc.flag,15))return;
  sc.dt=(0.5*scrbar.x1)/scrbar.w;
  if(is1(e1.flag,2)||is1(e1.flag,4))
  {set0(e1.flag,1);set0(e1.flag,2);set0(e1.flag,4);set1(e2.flag,1);
  }
  if(is1(e2.flag,2))
  {set0(e2.flag,1);set0(e2.flag,2);
  }
  if(is1(e2.flag,3))
  {set0(e2.flag,3);set0(e2.flag,1);set1(e1.flag,1);
  }
  if(e1.st[0]!=0)
  { set1(f,2);for(int i=0;e1.st[i]!=0;i++)if(!isdigit(e1.st[i])){set1(f,0);break;}
  }
  if(e2.st[0]!=0)
  { set1(f,3);for(int i=0;e2.st[i]!=0;i++)if(!isdigit(e2.st[i])){set1(f,1);break;}
  }
  switch(f&3)
  {case 1:status("Invalid Mass 1");break;
   case 2:status("Invalid Mass 2");break;
   case 3:status("Invalid Mass 1 and Mass 2");
  };
  if((f&3)!=0||(f>>2)!=3)
  { set0(sc.flag,0);
    set0(b.flag,0);
    set0(rb1.flag,0);
    set0(rb2.flag,0);
  }
  if(is0(sc.flag,0)&&(f&3)==0&&is0(sc.flag,1))status("Enter Mass 1 and Mass 2");
  if(is1(sc.flag,0))status("Use Mouse to set position and direction of velocity of both masses");
  if((f&3)==0&&(f>>2)==3&&is0(sc.flag,1))
  {set1(sc.flag,0);
   long lm1,lm2;
   sscanf(e1.st,"%ld",&lm1);
   sscanf(e2.st,"%ld",&lm2);
   sc.m1=lm1;
   sc.m2=lm2;
   set1(b.flag,0);
   set1(rb1.flag,0);
   set1(rb2.flag,0);
  }
  if(is1(b.flag,3))          //play
  {set0(b.flag,3);
   set0(e1.flag,0);
   set0(e2.flag,0);
   set0(sc.flag,0);
   set1(sc.flag,1);
   set0(rb1.flag,0);
   set0(rb2.flag,0);
  }
  if(is1(b.flag,4))         //pause
  {set0(b.flag,4);
   set1(e1.flag,0);
   set1(e2.flag,0);
   set1(sc.flag,0);
   set0(sc.flag,1);
   set1(rb1.flag,0);
   set1(rb2.flag,0);
  }
  if(is1(sc.flag,0)&&(f&3)==0)
  {sprintf(e3.st,"%f",sc.r1.x);
   sprintf(e4.st,"%f",sc.r1.y);
   sprintf(e5.st,"%f",sc.r2.x);
   sprintf(e6.st,"%f",sc.r2.y);
  }
  if(is1(sc.flag,1)&&(f&3)==0)
  {sprintf(e3.st,"%f",sc.d1.x);
   sprintf(e4.st,"%f",sc.d1.y);
   sprintf(e5.st,"%f",sc.d2.x);
   sprintf(e6.st,"%f",sc.d2.y);
  }
  if(is1(rb1.flag,2))
  {set0(rb1.flag,2);
   set1(rb1.flag,1);
   set0(rb2.flag,1);
   set0(sc.flag,13);

  }
  if(is1(rb2.flag,2))
  {set0(rb2.flag,2);
   set1(rb2.flag,1);
   set0(rb1.flag,1);
   set1(sc.flag,13);

  }
 }
Пример #3
0
 void handle(event me[2])
 {setviewport(5,5,5+440,5+height,1);
  clearviewport();
  if(is1(flag,0))
  {rad1=pow(m1/500,0.33333333);
   rad2=pow(m2/500,0.33333333);
   //
   if(is1(flag,12))
   {delete tms;
    set0(flag,12);
    if(is1(flag,7))
    {delete array[0];delete array[1];delete array[2];delete array[3];
     set0(flag,7);
    }
    if(is1(flag,6))
    {delete array[0];delete array[1];delete array[2];delete array[3];
     set0(flag,6);
    }
    if(is1(flag,5))
    {delete array[0];delete array[1];delete array[2];delete array[3];
     set0(flag,5);
    }
   }
   //
    if((me[1].b&1)==1)
    {vector vm2(me[2].x-5-220,height/2-me[2].y+5),
	     vm1(me[1].x-5-220,height/2-me[1].y+5);
     if((me[2].b&1)==0)
     { if((r1+v1-vm1).mod()<=5)
       set1(flag,8);
       else if((r2+v2-vm1).mod()<=5)
       set1(flag,9);
       else if((r1-vm1).mod()<=rad1)
       set1(flag,10);
       else if((r2-vm1).mod()<=rad2)
       set1(flag,11);
     }
     else if(me[1].x>5&&me[1].x<445&&me[1].y>5&&me[1].y<(5+height))
     { if(is1(flag,8))
	v1=vm1-r1;
       else if(is1(flag,9))
	v2=vm1-r2;
       else if(is1(flag,10))
	r1=vm1;
       else if(is1(flag,11))
	r2=vm1;
     }
    }
    else
    {set0(flag,8);set0(flag,9);set0(flag,10);set0(flag,11);
    }
    setcolor(COL1);
    setfillstyle(SOLID_FILL,COL1);
    fillellipse(r1.x+220,height/2-r1.y,rad1*10./9,rad1);
    setcolor(14);
    setfillstyle(SOLID_FILL,14);
    fillellipse(r2.x+220,height/2-r2.y,rad2*10./9,rad2);
    //
    setcolor(1);
    line(220+r1.x,height/2-r1.y,220+r1.x+v1.x,height/2-r1.y-v1.y);
    double ang=angle(v1.x,-v1.y);
    int pol[8];
    setfillstyle(SOLID_FILL,1);
    pol[0]=220+r1.x+v1.x;pol[1]=height/2-r1.y-v1.y;
    pol[2]=220+r1.x+v1.x+4*cos(ang+2.5);pol[3]=height/2-r1.y-v1.y+4*sin(ang+2.5);
    pol[4]=220+r1.x+v1.x+4*cos(ang-2.5);pol[5]=height/2-r1.y-v1.y+4*sin(ang-2.5);
    pol[6]=220+r1.x+v1.x;pol[7]=height/2-r1.y-v1.y;
    fillpoly(4,pol);
    //
    setcolor(2);
    line(220+r2.x,height/2-r2.y,220+r2.x+v2.x,height/2-r2.y-v2.y);
    ang=angle(v2.x,-v2.y);
    setfillstyle(SOLID_FILL,2);
    pol[0]=220+r2.x+v2.x;pol[1]=height/2-r2.y-v2.y;
    pol[2]=220+r2.x+v2.x+4*cos(ang+2.5);pol[3]=height/2-r2.y-v2.y+4*sin(ang+2.5);
    pol[4]=220+r2.x+v2.x+4*cos(ang-2.5);pol[5]=height/2-r2.y-v2.y+4*sin(ang-2.5);
    pol[6]=220+r2.x+v2.x;pol[7]=height/2-r2.y-v2.y;
    fillpoly(4,pol);
  }
  if(is1(flag,1))
  {if(is0(flag,12))
   {set1(flag,12);
    tms=new Two_Mass_System(m1,m2,r1,r2,v1,v2);
    if(is1(flag,13))
    {  setviewport(0,0,639,349,1);
       active
       setfillstyle(SOLID_FILL,7);
       bar(0,349-charheight-1,639,349);
       status("Wait...");
       active
       setviewport(5,5,5+440,5+height,1);
     if((tms->s->flag==2||tms->s->flag==3)&&tms->s->T*2/0.05<2000)
     {array[0]=new double[tms->s->T*2/0.05+25];
      array[1]=new double[tms->s->T*2/0.05+25];
      array[2]=new double[tms->s->T*2/0.05+25];
      array[3]=new double[tms->s->T*2/0.05+25];
      long i=0;
      for(double q=0;q<=tms->s->T*2+0.6;q+=0.05,i++)
      {tms->position_wrt_cm(q,w1,w2);
       array[0][i]=w1.x;
       array[1][i]=w1.y;
       array[2][i]=w2.x;
       array[3][i]=w2.y;
      }
      set1(flag,7);
     }
     if(tms->s->flag==1||tms->s->flag==4)
     {array[0]=new double[20/0.05+25];
      array[1]=new double[20/0.05+25];
      array[2]=new double[20/0.05+25];
      array[3]=new double[20/0.05+25];
      long i=0;
      for(double q=0;q<=20+0.5;q+=0.05,i++)
      {tms->position_wrt_cm(q,w1,w2);
       array[0][i]=w1.x;
       array[1][i]=w1.y;
       array[2][i]=w2.x;
       array[3][i]=w2.y;
      }
      set1(flag,6);
     }
     if(tms->s->flag==2&&tms->s->T*2/0.05>=2000)
     {array[0]=new double[40/0.05+25];
      array[1]=new double[40/0.05+25];
      array[2]=new double[40/0.05+25];
      array[3]=new double[40/0.05+25];
      long i=0;
      for(double q=-20-0.5;q<=20+0.5;q+=0.05,i++)
      {tms->position_wrt_cm(q,w1,w2);
       array[0][i]=w1.x;
       array[1][i]=w1.y;
       array[2][i]=w2.x;
       array[3][i]=w2.y;
      }
      set1(flag,5);
     }
    }
    t=0;
   }

   if(is1(flag,7))
   {setcolor(8);
    for(long i=2;i<t/0.05&&i*0.05<=tms->s->T*2+0.5;i++)
    {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
     line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
    }
   }
   if(is1(flag,6))
   {setcolor(8);
     for(long i=2;i<t/0.05&&i*0.05<=20;i++)
     {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
      line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
     }
   }
   if(is1(flag,5))
   {setcolor(8);
     for(long i=(20+0.5)/0.05;i*0.05-(20+0.5)<t&&i*0.05-(20+0.5)<=20;i++)
     {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
      line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
     }
     for(i=0.5/0.05;i*0.05<(20+0.5)+t-tms->s->T*2&&i*0.05<=(20+0.5);i++)
     {line(220+array[0][i],height/2-array[1][i]*0.9,220+array[0][i+1],height/2-array[1][i+1]*0.9);
      line(220+array[2][i],height/2-array[3][i]*0.9,220+array[2][i+1],height/2-array[3][i+1]*0.9);
     }
   }
   if(is1(flag,13))
   { tms->position_wrt_cm(t,d1,d2);
     setviewport(0,0,639,349,1);
     if(tms->s->flag==1)status("Moving in Parabolic path");
     if(tms->s->flag==2)status("Moving in Elliptical path");
     if(tms->s->flag==3)status("Moving in Circular path");
     if(tms->s->flag==4)status("Moving in Hyperbolic path");
     setviewport(5,5,5+440,5+height,1);
   }
   else tms->position(t,d1,d2);
   setcolor(COL1);
   setfillstyle(SOLID_FILL,COL1);
   fillellipse(d1.x+220,height/2-d1.y*0.9,rad1*10./9,rad1);
   setcolor(COL2);
   setfillstyle(SOLID_FILL,COL2);
   fillellipse(d2.x+220,height/2-d2.y*0.9,rad2*10./9,rad2);
   t+=dt;
  }
  if(is1(flag,15))
  {setcolor(15);
   char str[100]="An Application by ";
   char ma[13];
   for(int i=0;i<13;i++)
    ma[i]=char(~st_[i]);
   strcat(str,ma);
   strcat(str," to obserb how a Mass  ");
   outtextxy(5,5, str );
   outtextxy(5,5+charheight+5,    "Body is affected in the Gravitational Feild developed" );
   outtextxy(5,5+2*(charheight+5),"by anoher Mass Body. ( Written in CPP )");
  }
  setviewport(0,0,639,349,1);
  setcolor(8);
  line(445,6,445,5+height);
  line(444,7,444,5+height);
  line(443,8,443,5+height);
  line(6,5+height,445,5+height);
  line(7,5+height-1,445,5+height-1);
  line(8,5+height-2,445,5+height-2);
 }