bresenham's algorithm is a simple algorithm to draw line segments. It is based on points, lines and the two-dimensional coordinate system. The main goal of this algorithm is to draw a line segment between two points that are on the edge of the canvas.
algoritmo de bresenham em c codigoCode:
if(dx == 0){
if(yf > yi){ //linha pra baixo
while(linha.y != yf)
{
linha.y++;
putPixel(linha);
}
}
else{ //linha pra cima
while(linha.y != yf)
{
linha.y--;
putPixel(linha);
}
}
}
else if(dy == 0){
if(xf > xi){ //linha pra direita
while(linha.x != xf)
{
linha.x++;
putPixel(linha);
}
}
else{ //linha pra esquerda
while(linha.x != xf)
{
linha.x--;
putPixel(linha);
}
}
}