Master the fundamental concepts of software rasterizer through this focused micro-challenge.
In 1962, Jack Bresenham developed an algorithm to draw straight lines on a pixel grid. Given endpoints (x0, y0) and (x1, y1), which pixels best approximate the ideal line?
The naive approach uses y = mx + b, computing and rounding y for each integer x. That requires floating-point multiply and divide on every pixel.
Bresenham's insight: track an integer error term instead of computing y directly. For slopes between 0 and 1:
cLoading…
For example, drawing from (0,0) to (7,3) uses only integer addition and subtraction. Other octants swap x/y or reverse step direction, but the error-term logic stays the same.
You will implement Bresenham's algorithm for a line with slope between 0 and 1, printing each plotted pixel coordinate. This task asks you to output the full pixel list for endpoints read from stdin. The integer-only path you write here is still used inside Cairo, Skia's software backend, and embedded displays.
Write a C program that implements Bresenham's line algorithm for the first octant (0 <= slope <= 1).
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
Every task includes starter code, theory, and hidden tests so you can implement and verify locally in the browser.
How it works