Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DrawLine(Coordenadas *Pinicio, Coordenadas *Pfinal, Cor *cor)
- {
- float x = Pinicio->GetX();
- float y = Pinicio->GetY();
- float xf = Pfinal->GetX();
- float yf = Pfinal->GetY();
- int dx = abs( Pfinal->GetX() - Pinicio->GetX() ); //distancia entre as coordenadas Xinicial e Xfinal
- int dy = abs( Pfinal->GetY() - Pinicio->GetY()); //distancia entre as coordenadas Yinicial e Yfinal
- int incX=0;
- int incY=0;
- int d= 0;
- int movimentaE = 0; // movimentasse para o E(east)
- int movimentaNE = 0; // movimentasse para o NE(east)northeast
- if (xf >= x) // X cresce
- {
- incX= 1;
- }
- else // X descresce
- {
- incX=-1;
- }
- if (yf >= y) // Y cresce
- {
- incY = 1;
- }
- else // Y descresce
- {
- incY = -1 ;
- }
- if( (dx==0) || (dy==0) )
- {
- DrawLineConst(Pinicio,Pfinal,cor);
- }
- else
- {
- if(dx >= dy)
- {
- d= (2*dy - dx);
- movimentaE = 2*dy;
- movimentaNE = 2*(dy-dx);
- while(x!=xf)
- {
- if(d <= 0)
- {
- d=d+movimentaE;
- x+=incX;
- }
- else
- {
- d=d+movimentaNE;
- x=x+ incX;
- y=y+incY;
- }
- Coordenadas *coordenadas = new Coordenadas(x,y);
- PutPixel(coordenadas,cor);
- }
- }
- else if(dy>=dx)
- {
- d= (2*dx - dy);
- movimentaE = 2*dx;
- movimentaNE = 2*(dx-dy);
- while(y!=yf)
- {
- if(d <=0)
- {
- d+=movimentaE;
- y+=incY;
- }
- else
- {
- d+=movimentaNE;
- y+=incY;
- x+=incX;
- }
- Coordenadas *coordenadas = new Coordenadas(x,y);
- PutPixel(coordenadas,cor);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement