3 ms·
With the error initialized to zero, this algorithm will always step immediately after drawing the first pixel, which will cause that pixel to "stick out". y
by rep_lodsb 5y ago
With the error initialized to zero, this algorithm will always step immediately after drawing the first pixel, which will cause that pixel to "stick out".
y += 1; // y == 1
err += 2*y + 1; // err == 3
x -= 1; // x == radius-1
err -= 2*x + 1; // err == 2-(2*(radius-1))
You could compare the absolute value of the new and old error, or start with err = -(radius-1) instead.
And you don't need calculus to come up with the algorithm, just simple high school algebra: (x+1)² - x² = 2x + 1.