Program to Simulate BRESENHAM’S ALGORITHM FOR LINE DRAWING.
AIM:
To write a program in C to draw a line using Bresenham’s algorithm.
ALGORITHM:
1. Start the program.
2. Initialize the variables.
3. Call the initgraph() function.
4. Input the two line end-points and store the left end-point in (x0, y0).
5. Plot the point (x0, y0).
6. Calculate the constants Δx, Δy, 2Δy, and (2Δy - 2Δx) and get the first value for the decision parameter as:
7. At each xk along the line, starting at k = 0, perform the following test. If pk < 0, the next point to plot is (xk+1, yk) and
8. Otherwise, the next point to plot is (xk+1, yk+1) and Repeat step 4 (Δx – 1) times.
xypΔ−Δ=20yppkkΔ+=+21xyppkkΔ−Δ+=+221
9. Stop the graphics driver.
10. Stop the program.
Program:
- C
- C++
- Java
- Python
- C#
- PHP
- Javascript
Enter the x-coordinate of the first point ::40
Enter the y-coordinate of the first point ::50
Enter the x-coordinate of the second point ::60
Enter the y-coordinate of the second point ::80
RESULT:
Thus the program in C to draw the line by using Bresenham’s algorithm was done successfully.