Bresenham's
Midpoint Algorithm

public void circleMidpoint(
    int x0, int y0, int radius, Color c) {

    int pix = c.getRGB();
    int x = 0;
    int y = radius;
    int d = (5 - 4*radius)/4;

    circlePoints(x0, y0, x, y, pix);
    while (x < y) {
        if (d < 0) {
            d += 2*x+3;
            x += 1;
        } else {
            d += 2*(x-y)+5;
            x += 1;
            y -= 1;
        }
        circlePoints(x0, y0, x, y, pix);
    }
}
    private void circlePoints(
        int cx, int cy,
        int x, int y, int pix) {
        if (x == 0) {
            raster.setPixel(act, cx, cy + y);
            raster.setPixel(pix, cx, cy - y);
            raster.setPixel(pix, cx + y, cy);
            raster.setPixel(pix, cx - y, cy);
        } else
        if (x <= y) {
            raster.setPixel(act, cx + x, cy + y);
            raster.setPixel(pix, cx - x, cy + y);
            raster.setPixel(pix, cx + x, cy - y);
            raster.setPixel(pix, cx - x, cy - y);
            if (x < y) {
               raster.setPixel(pix, cx + y, cy + x);
               raster.setPixel(pix, cx - y, cy + x);
               raster.setPixel(pix, cx + y, cy - x);
               raster.setPixel(pix, cx - y, cy - x);
            }
        }
    }
Lecture 6 Slide 11 6.837 Fall '98