Modified Incremental Line
void Line(int x0, int y0, int x1, int y1, int value) {
int x, y;
float dy = y1 - y0;
float dx = y1 - x0;
float m = dy / dx;
for (x = x0; x < x1; x++) {
WritePixel(x, Round(y), value);
y = y + m;
}
}
Midpoint Line
void MidpointLine(int x0, int y0, int x1, int y1, int value) {
int dx = x1 - x0;
int dy = y1 - y0;
int d = 2 * dy - dx;
int incrE = 2 * dy;
int incrNE = 2 * (dy - dx);
int x = x0;
int y = y0;
writePixel(x, y, value);
while (x < x1) {
if (d <= 0) //East Case
d = d + incrE;
else // Northeast Case
d = d + incrNE;
y++;
x++;
writePixel(x, y, value);
}
}
Midpoint Circle
void MidpointCircle(int r){
int x = 0;
int y = r;
float d = 5/4 - r;
writePixel(x, y);
while (x < y) {
if (d <= 0) // E is chosen
d = d + (2 * x + 3);
else { // SE is chosen
y--;
d = d + (2 * x - 2 * y + 5);
}
x++;
writePixel(x, y);
}
}