public void drawLine(int x1, int y1, int x2, int y2, Graphics g) {
        // get screen bounds
        int xoffset = getWidth();
        int yoffset = getHeight();

        // relocate line within screen bounds
        int mx = clampToCircle(x1, xoffset) - x1;
        int my = clampToCircle(y1, yoffset) - y1;
        x1 += mx;
        x2 += mx;
        y1 += my;
        y2 += my;

        // iteratively draw successive segments within screen bounds
        // fraction is the ratio to the next point where you go out of bounds
        double fraction;
        do {
            double xfraction = 2;
            if (x2 != x1) {
                xfraction = (((x2 > x1) ? xoffset : 0) - x1) / (double) (x2 - x1);
            }
            double yfraction = 2;
            if (y2 != y1) {
                yfraction = (((y2 > y1) ? yoffset : 0) - y1) / (double) (y2 - y1);
            }
            fraction = Math.min(xfraction, yfraction);
            if (fraction < 1) {
                // draw up to fraction
                int x3 = x1 + (int)Math.round(fraction * (x2 - x1));
                int y3 = y1 + (int)Math.round(fraction * (y2 - y1));
                g.drawLine(x1, y1, x3, y3);

                // recenter remaining segment in screen bounds
                mx = (int) Math.round(clampToCircle(x3 + ((x2 > x1) ? EPSILON : -EPSILON), xoffset)) - x3;
                my = (int) Math.round(clampToCircle(y3 + ((y2 > y1) ? EPSILON : -EPSILON), yoffset)) - y3;
                x1 = x3 + mx;
                x2 += mx;
                y1 = y3 + my;
                y2 += my;
            }
        } while (fraction < 1);

        g.drawLine(x1, y1, x2, y2);
    }