document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. void DrawLine(Coordenadas *Pinicio, Coordenadas *Pfinal, Cor *cor)
  2. {
  3.      float x  = Pinicio->GetX();
  4.      float y  = Pinicio->GetY();
  5.      float xf = Pfinal->GetX();
  6.      float yf = Pfinal->GetY();
  7.      int dx = abs( Pfinal->GetX() - Pinicio->GetX() ); //distancia entre as coordenadas Xinicial e Xfinal
  8.      int dy = abs( Pfinal->GetY() -  Pinicio->GetY()); //distancia entre as coordenadas Yinicial e Yfinal
  9.      int incX=0;
  10.      int incY=0;
  11.      int d= 0;
  12.      int movimentaE = 0; // movimentasse para o E(east)
  13.      int movimentaNE = 0; // movimentasse para o NE(east)northeast
  14.  
  15.     if (xf >= x) // X cresce
  16.     {
  17.         incX= 1;
  18.     }
  19.     else     // X descresce
  20.     {
  21.         incX=-1;
  22.  
  23.     }
  24.     if (yf >= y) // Y cresce
  25.     {
  26.         incY = 1;
  27.     }
  28.     else // Y descresce
  29.     {
  30.         incY = -1 ;
  31.  
  32.     }
  33.  
  34.     if( (dx==0) || (dy==0) )
  35.     {
  36.       DrawLineConst(Pinicio,Pfinal,cor);
  37.     }
  38.  
  39.     else
  40.     {
  41.    
  42.        if(dx >= dy)
  43.        {
  44.         d= (2*dy - dx);
  45.         movimentaE = 2*dy;
  46.         movimentaNE = 2*(dy-dx);
  47.             while(x!=xf)
  48.             {  
  49.                if(d <= 0)
  50.                {
  51.                     d=d+movimentaE;
  52.                     x+=incX;
  53.                }
  54.                else
  55.                {
  56.                     d=d+movimentaNE;
  57.                     x=x+ incX;
  58.                     y=y+incY;
  59.  
  60.                }
  61.  
  62.                Coordenadas *coordenadas = new Coordenadas(x,y);
  63.                         PutPixel(coordenadas,cor);
  64.             }
  65.  
  66.        }
  67.        else if(dy>=dx)
  68.        {
  69.  
  70.            d= (2*dx - dy);
  71.            movimentaE = 2*dx;
  72.            movimentaNE = 2*(dx-dy);
  73.  
  74.                 while(y!=yf)
  75.                 {
  76.                
  77.                     if(d <=0)
  78.                     {
  79.                         d+=movimentaE;
  80.                         y+=incY;
  81.  
  82.                     }
  83.                     else
  84.                     {
  85.                         d+=movimentaNE;
  86.                         y+=incY;
  87.                         x+=incX;
  88.  
  89.                     }
  90.  
  91.                Coordenadas *coordenadas = new Coordenadas(x,y);
  92.                         PutPixel(coordenadas,cor);
  93.  
  94.                }
  95.      }
  96.  
  97.  
  98.        }
  99.  
  100.     }
');