Computer Graphics, MFC circle ZZ

Source: Internet
Author: User

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
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.