/* * Program to draw circles in a 2D array of characters, * printing the array to the screen */ #include #include #define WIDTH 79 #define HEIGHT 24 void clear (char screen[][HEIGHT]) { int i, j; for (i=0; i= WIDTH) return WIDTH-1; if (a < 0) return 0; } int safej (int a) { if (a >= HEIGHT) return HEIGHT-1; if (a < 0) return 0; } void circle (char screen[][HEIGHT], int i, int j, int radius) { float x, y; int di, dj; for (x=0.0; x<=1.0; x+=0.01) { y = sqrt (1.0 - x*x); di = (int) (x * radius * 1.7); dj = (int) (y * radius); screen[safei(i + di)][safej(j + dj)] = '*'; screen[safei(i + di)][safej(j - dj)] = '*'; screen[safei(i - di)][safej(j + dj)] = '*'; screen[safei(i - di)][safej(j - dj)] = '*'; } } int main () { char screen[WIDTH][HEIGHT]; clear (screen); circle (screen, 40, 12, 10); circle (screen, 40, 10, 4); circle (screen, 2, 5, 10); circle (screen, 40, 12, 10); print (screen); }