(Midpoint Circle Algorithm) Below is the circle routine that appears on page 102 of Hearn and Baker (modified slightly to work on my MAC). void circleMidpoint(int xCenter, int yCenter, int radius){ int x = 0; int y = radius; int p = 1 - radius; void circlePlotPoints(int xCenter, int yCenter, int x, int y); /* Plot first set of points */ circlePlotPoints(xCenter, yCenter, x, y); while (x < y) { x++; if (p < 0) p += 2*x + 1; else { y--; p += 2 * (x-y) + 1; } circlePlotPoints(xCenter, yCenter, x, y); } } void circlePlotPoints(int xCenter, int yCenter, int x, int y){ // SetColorPixel(x, y, r, g, b); sets the pixel (x, y) to rgb (r, g, b) SetColorPixel(xCenter + x, yCenter + y, 0, 0, 0); SetColorPixel(xCenter - x, yCenter + y, 0, 0, 0); SetColorPixel(xCenter + x, yCenter - y, 0, 0, 0); SetColorPixel(xCenter - x, yCenter - y, 0, 0, 0); SetColorPixel(xCenter + y, yCenter + x, 0, 0, 0); SetColorPixel(xCenter - y, yCenter + x, 0, 0, 0); SetColorPixel(xCenter + y, yCenter - x, 0, 0, 0); SetColorPixel(xCenter - y, yCenter - x, 0, 0, 0); }Assume that you have a function: void HLine(int x1, int x2, int y);that efficiently draws the horizontal line from (x1, y) to (x2, y). For each of the shapes on below, show the changes you would make, to the circle code, to generate the shape shown. USE HLine.
|