Esempio n. 1
0
File: t.c Progetto: adammaj1/c
// compute turn and save to array
int iSaveTurn(int iX, int iY, int NumberOfRay)
{
  

  double dXt; // = dX-dAlfaX = translation
  double dYt; // = dY-dAlfaY
  double turn; 
  // distance to alfa fixed point ( target set )
  int iDistance;
  double dDistance2; // 
  

  dXt = ( GiveZx(iX) - dAlfaX);
  dYt = ( GiveZy(iY) - dAlfaY );
  dDistance2 = dXt*dXt + dYt*dYt;
  if (dMaxDistance2Alfa2>dDistance2) 
    {

      turn =  GiveTurn(  dXt, dYt);
      iDistance = (int)(sqrt(dDistance2)/PixelWidth);
      // printf("Zx = %f; Zy= %f iDistance = %d\n",GiveZx(iX),GiveZx(iY), iDistance); // debug info 
      if (iDistance<=iMaxDistance2Alfa) RaysTurns[iDistance][NumberOfRay] = turn;
    }
  return 0;

}
Esempio n. 2
0
File: t.c Progetto: adammaj1/c
/*
finds offset in turns of parabolic Julia set 

Method is described here :
 Complex Dynamics by Lennart Carleson,Theodore Williams Gamelin 
 page 40

------------Explanation and code by Wolf Jung ------------------------
> The problem is that for q = 10 it is computing 1025 coefficients
> where only 12 are needed. Try the following and compare the
> results with the existing program:
> * Allocate a matrix array a_mn with m <= q and n <= q+1.
> * Set a_11 = lambda , a_12 = 1 , and a_13 ... a_1,q+1 = 0.
> * For m = 1 to q-1 for n = 1 to q+1
>  a_m+1,n = lambda*a_mn + sum a_mk * a_m,n-k
>  where the summation is from k = 1 to n-1.
> Then a_mn is the coefficient of z^n in f^m , with
> f = lambda*z + z^2 . So the desired A is a_q,q+1 .
> 
> In fact you only need one row instead of a quadratic array
> by redefining the variables:
> * Allocate an array a_n with n <= q+1.
> * Set a_1 = lambda , a_2 = 1 , and a_3 ... a_q+1 = 0.
> * For m = 1 to q-1 for n = q+1 down to 1 (not up !)
>  a_n = lambda*a_n + sum a_k * a_n-k
>  where the summation is from k = 1 to n-1.
> 
> Or in c++:
> int k, m, n; complex a[q+2];
> a[1] = lambda; a[2] = complex(1.0);
> for (n = 3; n <= q+1; n++) a[n] = 0;
> for (m = 1; m < q; m++) for (n = q+1; n; n--)
> { a[n] *= lambda;
>  for (k = 1; k < n; k++) a[n] += a[k]*a[n-k];
> }
> //Now a[q+1] = A with f^q(z) = z + a*z^(q+1) + ...
> 
>  Best regards,
> 
>  Wolf

*/
double GiveOffset(int p, int q )
{
  double complex a[iPeriodChild+2];
  double complex lambda;
  double t; // = Internal Angle In radians
  double offset;
  int k, m, n; // index of for loops
  double complex coeff;
  
  t = ((double)p/q) *2*M_PI; // from turns to radians
  lambda= (cos(t)+I*sin(t));
   // a[0]=0;
   a[1] = lambda; 
   a[2] = 1.0;
   for (n = 3; n <= q+1; n++) a[n] = 0;
   //
   for (m = 1; m < q; m++) 
     for (n = q+1; n; n--)
      { a[n] *= lambda;
        for (k = 1; k < n; k++) 
          a[n] += a[k]*a[n-k]; // sum 
      }
   //Now a[q+1] = A with f^q(z) = z + a*z^(q+1) + ...
   coeff = a[q+1];
   offset= -GiveTurn(creal(coeff), cimag(coeff))/q;
  return offset;


}
Esempio n. 3
0
int GameManager::ChangeTurn(int finishedPlayerID)
{
    //int nextTurnPlayerID;

    if (finishedPlayerID == 1)
    {
//         GiveTurn(2);
//         return 2;
     }

    if (finishedPlayerID==2)
    {
        GiveTurn(1);

        return 1;
    }



    //return nextTurnPlayerID;
}
Esempio n. 4
0
File: t.c Progetto: adammaj1/c
int ColourNewTrap(unsigned char A[])
{
 
  unsigned int ix, iy; // pixel coordinate 
  double Zx, Zy; //  Z= Zx+ZY*i;
  double Zxt, Zyt;
  unsigned i; /* index of 1D array */
  double dDistance2; // = sqr( distance to alfa)
  int iDistance;
  double turn;
   
  for(iy=iyMin;iy<=iyMax;++iy) 
    {
      Zy = GiveZy(iy);
      Zyt = Zy -dAlfaY;// translation near fixed point alfa
      for(ix=ixMin;ix<=ixMax;++ix) 
        {
 
          // from screen to world coordinate 
          Zx = GiveZx(ix);
          
          // translation near fixed point alfa
          Zxt = Zx - dAlfaX; 
          //
          turn =  GiveTurn(Zxt, Zyt);         
          dDistance2 = Zxt*Zxt + Zyt*Zyt ;
          iDistance = (int)(sqrt(dDistance2)/PixelWidth);
          // check if point z is inside triangle around arm of critical orbit 
          if ( dDistance2 < dMaxDistance2Alfa2 && turn>RaysTurns[iDistance][iPeriodChild-2] && turn<RaysTurns[iDistance][iPeriodChild-1]) 
	    { i = Give_i(ix, iy); /* compute index of 1D array from indices of 2D array */
              if ( A[i]==255) A[i]=0; // rays 
	      else A[i]= 255-A[i];   // mark the trap
	    }
        }
    }
 
 
 
  return 0;
}
Esempio n. 5
0
void GameManager::SetTwoPlayer()
{
    //하드코딩 
    m_PlayerList[1] = new Player(1, TEAM_A);
    m_PlayerList[2] = new Player(2, TEAM_B);


    m_Player1 = m_PlayerList[1];
    m_Player2 = m_PlayerList[2];

    auto objlayer = GET_OBJECT_LAYER;

    auto firstP = m_PlayerList.find(1);
    firstP->second->MakeTank(1, Vec2(500.0f, 100.0f));
    objlayer->AddTank(firstP->second->GetTank());


    auto secondP = m_PlayerList.find(2);
    secondP->second->MakeTank(2, Vec2(100.0f, 100.0f));
    objlayer->AddTank(secondP->second->GetTank());

    m_WhoseTurn = firstP->second->GetPlayerID();
    GiveTurn(m_WhoseTurn);
}
Esempio n. 6
0
File: t.c Progetto: adammaj1/c
// compute turn and save to array
// ray goes : from inf thru z0 thru z1 to alfa
// it means that external radius of z0 is greater than external radius of z0
// it does not mean that iDistance0 iDistance1 ( because ray can turn )
double SaveTurns(double Zx0, double Zy0, double Zx1, double Zy1, int NumberOfRay)
{
  double xt; // = x-dAlfaX = translation
  double yt; // = y-dAlfaY
  int iDistance, iDistance0, iDistance1;
  int iDistanceMax; //, iDistanceMin;
  double turn, turn0, turn1; //, turnMin;
  //double dStep; // step between turns
  //int iStep;   // = iDistanceMax - iDistanceMin;

  // compute/save turn of only one point
  // translation to alfa 
  xt= Zx0 - dAlfaX;
  yt= Zy0 - dAlfaY;
     
  iDistance0 = (int)(sqrt(xt*xt +  yt*yt)/PixelWidth);
  turn0 =  GiveTurn(  xt, yt);
  //if inside trap !! save turns to the RaysTurns array
  if ( iDistance0 <= iMaxDistance2Alfa && iDistance0 >0 ) 
    RaysTurns[iDistance0][NumberOfRay]= turn0; 
       

  // compute/save turn of only one point
  // translation to alfa 
  xt= Zx1 - dAlfaX;
  yt= Zy1 - dAlfaY;
      
  iDistance1 = (int)(sqrt(xt*xt +  yt*yt)/PixelWidth); 
  turn1 =  GiveTurn(  xt, yt);
  //if inside trap !! save turns to the RaysTurns array
  if ( iDistance1 <= iMaxDistance2Alfa && iDistance1 >0 ) 
    RaysTurns[iDistance1][NumberOfRay]= turn1; 

       
  // if one of 2 ends is inside trap 
  // then fill the gaps ( where turn <0 ; it means not filled )
  // and save turns to the RaysTurns array
  if ( iDistance0 <= iMaxDistance2Alfa || iDistance1 <= iMaxDistance2Alfa)
    { 
      // all points are not alfa ; both iDistance >0
      //    if ( iDistance0 >0 && iDistance1 > 0  ) 
      /*       {*/
      /*         iStep = iDistanceMax - iDistanceMin;*/
      /*         if (turn0>turn1) */
      /*            {dStep = (turn0-turn1)/iStep; turnMin = turn1;}*/
      /*            else {dStep = (turn1-turn0)/iStep; turnMin=turn0;}*/
      /*         for (iDistance=iMaxDistance2Alfa; iDistance<iDistance1; iDistance++) RaysTurns[iDistance][NumberOfRay] = turnMin+(iDistance-iDistance1)*dStep;*/
      /*         */
      /*       }*/
      /*     */
      // both ends are inside trap 
      // one of 2 points is alfa, so one iDistance ==0
      if (iDistance1==0 ) 
	{iDistanceMax=iDistance0;  turn = turn0;}
      else {iDistanceMax=iDistance1;  turn = turn1;}
      // copy first positive value  to all cells before it = straight line 
      for (iDistance=0; iDistance<iDistanceMax; iDistance++) RaysTurns[iDistance][NumberOfRay] = turn;
        
    }

  return 0;

}
Esempio n. 7
0
File: t.c Progetto: adammaj1/c
unsigned char ComputeColor(unsigned int ix, unsigned int iy, int IterationMax)
{ 
  // check behavour of z under fc(z)=z^2+c
  // using 2 target set:
  // 1. exterior or circle (center at origin and radius ER ) 
  // as a target set containing infinity = for escaping points ( bailout test)
  // for points of exterior of julia set
  // 2. interior of circle with center = alfa and radius dMaxDistance2Alfa
  // as a target set for points of interior of Julia set 
  //  Z= Zx+ZY*i;

  double Zx2, Zy2;
  int i=0;
  //int j; // iteration = fc(z)
  double d2 ; /* d2= (distance from z to Alpha)^2   */
  double Zxt,Zyt ; // 
  double Zx, Zy;
  double turn;
  int iDistance;
  
  
  // from screen to world coordinate 
  Zx = GiveZx(ix);
  Zy = GiveZy(iy);
  /* distance from z to Alpha  */
  Zxt=Zx-dAlfaX;
  Zyt=Zy-dAlfaY;
  d2=Zxt*Zxt +Zyt*Zyt;
  if (d2<dMaxDistance2Alfa2) 
    {
      iDistance = (int)(sqrt(d2)/PixelWidth);
      if (iDistance<iMaxDistance2Alfa)
	{ 
	  turn =  GiveTurn(Zxt, Zyt);
	  if ( turn>RaysTurns[iDistance][iPeriodChild-2] && turn<RaysTurns[iDistance][iPeriodChild-1])
	    return  iColorsOfInterior[i % iPeriodChild];
	}
    }

  // if not inside target set around attractor ( alfa fixed point )
  while (1 )
    { // then iterate 
      
      Zx2 = Zx*Zx; 
      Zy2 = Zy*Zy;
       
      // bailout test 
      if (Zx2 + Zy2 > ER2) return iColorOfExterior; // if escaping stop iteration
       
      // if not escaping or not attracting then iterate = check behaviour
      // new z : Z(n+1) = Zn * Zn  + C
      Zy = 2*Zx*Zy + Cy; 
      Zx = Zx2 - Zy2 + Cx; 
      //
      i+=1;
	 
      /* distance from z to Alpha  */
      Zxt=Zx-dAlfaX;
      Zyt=Zy-dAlfaY;
      d2=Zxt*Zxt +Zyt*Zyt;
      // check if fall into internal target set 
      if (d2<dMaxDistance2Alfa2) 
	{
	  iDistance = (int)(sqrt(d2)/PixelWidth);
	  if (iDistance<iMaxDistance2Alfa)
	    { 
	      turn =  GiveTurn(Zxt, Zyt);
	      if ( turn>RaysTurns[iDistance][iPeriodChild-2] && turn<RaysTurns[iDistance][iPeriodChild-1])
		return  iColorsOfInterior[i % iPeriodChild];
	    }
	}
    
      if (i > IterationMax) return 255;
      
      
    }

  return  iColorsOfInterior[i % iPeriodChild];   //
}