Computer Graphics (MFC) circle
Key points: Read 674 comments 0
Font size: large, medium, small
//////////////////////////////////////// ////////////////////////////
// Circle by the incircle integer algorithm //
//////////////////////////////////////// /////////////////////////////
Void roundmid (INT X1, int Y1, int R, CDC * PDC)
{
Int x = 0, y = R;
Int d = 1-r; // start point (0, R), next point midpoint (1, R-0.5), D = 1*1 + (R-0.5) * (R-0.5) -R * r = 1.25-r, D is only involved in integer calculation, so the fractional part can be omitted
While (Y> X) // y> X indicates the octal circle of area 2nd in the First quadrant.
{
PDC-> setpixel (x + X1, Y + Y1, RGB (, 0); // the center of the circle (x1, Y1). Add and translate the vertices directly and draw area 2.
PDC-> setpixel (Y + X1, x + Y1, RGB (255, 0, 0); // draw area 1
PDC-> setpixel (-x + X1, Y + Y1, RGB (, 0); // draw area 3
PDC-> setpixel (-y + X1, x + Y1, RGB (255, 0, 0); // draw area 4
PDC-> setpixel (-x + X1,-y + Y1, RGB (, 0); // draw the 5-Area
PDC-> setpixel (-y + X1,-x + Y1, RGB (255, 0, 0); // draw area 6
PDC-> setpixel (x + X1,-y + Y1, RGB (, 0); // Plot Area 7
PDC-> setpixel (Y + X1,-x + Y1, RGB (255, 0, 0); // draw 8 blocks
If (dsetpixel (x1, Y1, RGB (255,); // draw a circle to prove that the circle must occupy one pixel
While (yi> = xi) // cycles to 1/8 circles; Yi> = 0 to draw a circle
{
PDC-> setpixel (XI + X1, yi + Y1, RGB (, 0); // area 2, coordinate translation (x1, Y1) circle
PDC-> setpixel (yi + X1, Xi + Y1, RGB (255, 0, 0); // area 1
PDC-> setpixel (-xi + X1, yi + Y1, RGB (255, 0, 0); // Area 3
PDC-> setpixel (-yi + X1, Xi + Y1, RGB (255, 0, 0); // area 4
PDC-> setpixel (-yi + X1,-xi + Y1, RGB (255, 0); // area 5
PDC-> setpixel (-xi + X1,-yi + Y1, RGB (255, 0, 0); // Area 6
PDC-> setpixel (XI + X1,-yi + Y1, RGB (255, 0, 0); // Area 7
PDC-> setpixel (yi + X1,-xi + Y1, RGB (255, 0, 0); // area 8
If (DD = 0, dd0) // D is outside the circle; V is outside the circle or circle; D or V is selected; DD> 0, DV
Previous Article: make an analysis of the existing DDoS code (Attack Module)-CC
Next article: differences between resistance and Impedance