मुझे माफ़ कर दो अगर मेरी स्पष्टीकरण स्पष्ट नहीं थे, मैं फ्रेंच हूँ,)
void DrawFilledCircle(int circleDiameter, int circlePosX, int circlePosY)
{
const int FULL = (1 << 2);
const int HALF = (FULL >> 1);
int size = (circleDiameter << 2);// fixed point value for size
int ray = (size >> 1);
int dY2;
int ray2 = ray * ray;
int posmin,posmax;
int Y,X;
int x = ((circleDiameter&1)==1) ? ray : ray - HALF;
int y = HALF;
circlePosX -= (circleDiameter>>1);
circlePosY -= (circleDiameter>>1);
for (;; y+=FULL)
{
dY2 = (ray - y) * (ray - y);
for (;; x-=FULL)
{
if (dY2 + (ray - x) * (ray - x) <= ray2) continue;
if (x < y)
{
Y = (y >> 2);
posmin = Y;
posmax = circleDiameter - Y;
// Draw inside square and leave
while (Y < posmax)
{
for (X = posmin; X < posmax; X++)
setPixel(circlePosX+X, circlePosY+Y);
Y++;
}
// Just for a better understanding, the while loop does the same thing as:
// DrawSquare(circlePosX+Y, circlePosY+Y, circleDiameter - 2*Y);
return;
}
// Draw the 4 borders
X = (x >> 2) + 1;
Y = y >> 2;
posmax = circleDiameter - X;
int mirrorY = circleDiameter - Y - 1;
while (X < posmax)
{
setPixel(circlePosX+X, circlePosY+Y);
setPixel(circlePosX+X, circlePosY+mirrorY);
setPixel(circlePosX+Y, circlePosY+X);
setPixel(circlePosX+mirrorY, circlePosY+X);
X++;
}
// Just for a better understanding, the while loop does the same thing as:
// int lineSize = circleDiameter - X*2;
// Upper border:
// DrawHorizontalLine(circlePosX+X, circlePosY+Y, lineSize);
// Lower border:
// DrawHorizontalLine(circlePosX+X, circlePosY+mirrorY, lineSize);
// Left border:
// DrawVerticalLine(circlePosX+Y, circlePosY+X, lineSize);
// Right border:
// DrawVerticalLine(circlePosX+mirrorY, circlePosY+X, lineSize);
break;
}
}
}
void DrawSquare(int x, int y, int size)
{
for(int i=0 ; i<size ; i++)
DrawHorizontalLine(x, y+i, size);
}
void DrawHorizontalLine(int x, int y, int width)
{
for(int i=0 ; i<width ; i++)
SetPixel(x+i, y);
}
void DrawVerticalLine(int x, int y, int height)
{
for(int i=0 ; i<height ; i++)
SetPixel(x, y+i);
}
गैर पूर्णांक व्यास का उपयोग करने के लिए आपको नियत बिन्दु की शुद्धता को बढ़ाने या डबल मूल्यों का उपयोग कर सकते हैं। डीवाई 2 + (रे - एक्स) * (रे - एक्स) और रे 2 (डीएक्स² + डी² और आर²) के बीच अंतर के आधार पर एंटी-एलियास बनाने के लिए भी संभव होना चाहिए
बहुत स्पष्ट। – dmckee
क्या वास्तव में काम करता है? मैंने कोशिश की .. यह पूरी तरह से सर्कल भर नहीं है। क्या मैं कुछ भूल रहा हूँ ? किसी भी मामले में, नीचे कुछ सही उत्तर हैं। – AJed
@AJed यह जानने के लिए कि क्या आप कुछ खो रहे हैं, हमें आपके कोड को [अपने स्वयं के एक नए प्रश्न] में देखना होगा (http://stackoverflow.com/questions/ask) – AakashM