/* CIRCLE.C -- by Gary Neal, Jr. * * This function draws a circle on the graphics screen using floating * point math. */ #include "fgraph.h" /* Needed for ScreenWidth & ScreenHeight */ float angleIncr = 0.5; void Circle(int xOffset, int yOffset, int radius, unsigned char C) { float xPlot, yPlot; /* Current pixel being plotted */ float angle, angleRad; /* Current angle degrees & radiens */ /* Check limits for Angle Increment */ if (angleIncr < 1) angleIncr = 0.5; else if (angleIncr > 360.) angleIncr = 360.; for (angle = 0.; angle < 360.; angle += angleIncr) { /* Convert degrees to radiens */ angleRad = angle * (3.141592654 / 180); /* Convert polar to rectangular coordinates */ xPlot = (radius * cos(angleRad)) + xOffset; yPlot = (radius * sin(angleRad)) + yOffset; /* Check boundaries */ if (xPlot < 0) xPlot = 0; else if (xPlot >= ScreenWidth) xPlot = ScreenWidth - 1; if (yPlot < 0) yPlot = 0; else if (yPlot >= ScreenHeight) yPlot = ScreenHeight - 1; /* Plot the pixel on the graphics screen */ SetPixel((int)xPlot, (int)yPlot, C); } }