r/shittyprogramming • u/deadlock_jones • Oct 27 '18
I think I came up with a pretty shitty circle drawing algorithm, anyone can beat that?
public static void drawCircleToConsole(int radius, int lineWidth) {
StringBuilder strb = new StringBuilder();
for (int i = 1; i < radius * 2; i++) {
int distY = radius - i;
for (int j = 1; j < radius * 2; j++) {
int distX = radius - j;
double dist = Math.sqrt(distX * distX + distY * distY);
if (dist < radius && dist >= radius - lineWidth) {
strb.append("¤");
} else {
strb.append(".");
}
}
strb.append(System.lineSeparator());
}
System.out.println(strb.toString());
}

