0% found this document useful (0 votes)
97 views2 pages

Program To Draw A Circle Using Mid Point Algorithm

This C program uses the midpoint circle algorithm to draw a circle. It prompts the user to enter the center point and radius of the circle. It then calls the circleMidpoint function, which uses the midpoint test to iteratively determine and draw the pixels along the circle. The drawCircle function places red pixels at the appropriate x,y coordinates to render the full circle.

Uploaded by

reet_sandhu_2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views2 pages

Program To Draw A Circle Using Mid Point Algorithm

This C program uses the midpoint circle algorithm to draw a circle. It prompts the user to enter the center point and radius of the circle. It then calls the circleMidpoint function, which uses the midpoint test to iteratively determine and draw the pixels along the circle. The drawCircle function places red pixels at the appropriate x,y coordinates to render the full circle.

Uploaded by

reet_sandhu_2
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

www.eazynotes.com Gursharan Singh Tatla Page No.

/*** Program to Draw a Circle using Mid - Point Algorithm ***/

#include <stdio.h>
#include <dos.h>
#include <graphics.h>

void circleMidpoint(int, int, int);


void drawCircle(int, int, int, int);

void main()
{
int xc, yc, r;

int gd = DETECT, gm;


initgraph(&gd, &gm, "");

printf("Enter center coordinates of circle: ");


scanf("%d %d", &xc, &yc);
printf("Enter radius of circle: ");
scanf("%d", &r);

circleMidpoint(xc, yc, r);

getch();
}

void circleMidpoint(int xc, int yc, int r)


{
int x = 0, y = r;
int p = 1 - r;

while (x < y)
{
drawCircle(xc, yc, x, y);
x++;
www.eazynotes.com Gursharan Singh Tatla Page No. 2

if (p < 0)
p = p + 2 * x + 1;
else
{
y--;
p = p + 2 * (x - y) + 1;
}

drawCircle(xc, yc, x, y);


delay(50);
}
}

void drawCircle(int xc, int yc, int x, int y)


{
putpixel(xc+x, yc+y, RED);
putpixel(xc-x, yc+y, RED);
putpixel(xc+x, yc-y, RED);
putpixel(xc-x, yc-y, RED);
putpixel(xc+y, yc+x, RED);
putpixel(xc-y, yc+x, RED);
putpixel(xc+y, yc-x, RED);
putpixel(xc-y, yc-x, RED);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy