Answers for "what is Bresenham's line drawing algorithm"

C++
3

bresenham's line algorithm c++

void drawline(int x0, int y0, int x1, int y1)  
{  
    int dx, dy, p, x, y;  
    dx=x1-x0;  
    dy=y1-y0;  
    x=x0;  
    y=y0;  
    p=2*dy-dx;  
    while(x<x1)  
    {  
        if(p>=0)  
        {  
            putpixel(x,y,7);  
            y=y+1;  
            p=p+2*dy-2*dx; 
          	x+=1;
        }  
        else  
        {  
            putpixel(x,y,7);  
            p=p+2*dy;}  
            x+=1;  
        }  
}
Posted by: Guest on April-05-2021
2

Bresenham's line algorithm

static void bresenham(int x1, int y1, int x2, int y2) 
    { 
        int m_new = 2 * (y2 - y1); 
        int slope_error_new = m_new - (x2 - x1); 
      
        for (int x = x1, y = y1; x <= x2; x++) 
        { 
            System.out.print("(" +x + "," + y + ")n"); 
  
            // Add slope to increment angle formed 
            slope_error_new += m_new; 
  
            // Slope error reached limit, time to 
            // increment y and update slope error. 
            if (slope_error_new >= 0) 
            { 
                y++; 
                slope_error_new -= 2 * (x2 - x1); 
            } 
        } 
    }
Posted by: Guest on November-29-2020

Code answers related to "what is Bresenham's line drawing algorithm"

Browse Popular Code Answers by Language