Program for circle painting by the midpoint Bresenham Algorithm

Source: Internet
Author: User


# Include <math. h>
# Include <graphics. h>/* pre-defined library functions */
Void circlePoint (int x, int y)/* circle program by octal Method */
{
Circle (320 + x * 20,240 + y *, 3 );
Circle (320 + y * 20,240 + x *, 3 );
Circle (320-y * 20,240 + x * 20, 3 );
Circle (320-x * 20,240 + y * 20, 3 );
Circle (320-x * 20,240 + y * 20, 3 );
Circle (320-x * 20,240-y * 20, 3 );
Circle (320-y * 20,240-x * 20, 3 );
Circle (320 + y * 20,240-x *, 3 );
Circle (320 + x * 20,240-y *, 3 );
}
Void MidBresenhamcircle (int r)/* circle program of the midpoint Bresenham algorithm */
{
Int x, y, d;
X = 0; y = r; d = 1-r;/* calculate the initial value */
While (x <y)
{CirclePoint (x, y);/* draw points (x, y) and the other seven symmetry points in the octal circle */
If (d <0) d + = 2 * x + 3;/* determines whether to go or not in the non-maximum displacement direction based on the judgment of the error item d */
Else
{D + = 2 * (x-y) + 5;
Y --;
}
X ++;
Delay (900000 );
}/* While */
}
Main ()
{
Int I, j, r, graphmode, graphdriver;
Detectgraph (& graphdriver, & graphmode );
Initgraph (& graphdriver, & graphmode ,"");
Printf ("program whose circle is drawn by the mid-point Bresenhamcircle algorithm n");/* message */
Printf ("note | r | <= 11 ");
Printf ("n input radius value r :");
Scanf ("% d", & r );
Printf ("press any key to display the image ...");
Getch ();
Cleardevice ();
Setbkcolor (BLACK );
For (I = 20; I <= 620; I + = 20)/* use the double loop point function to draw the ordinate coordinates in the table */
For (j = 20; j <= 460; j ++)
Putpixel (I, j, 2 );
For (j = 20; j <= 460; j + = 20)

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.