C program for drawing a Circle using Midpoint Circle Algorithm - CGMT
Mid-pt-Algo-for-Circle.txt
File size: 1.01 KB
File content type: text/plain
Category: Practical Files
Subject: Computer Graphics and Multimedia
Midpoint circle drawing algorithm in C
// The program uses graphics.h which is generally available in Turbo C
#include<conio.h>
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm=DETECT;
int r,x,y,p,midx,midy;
clrscr();
initgraph(&gd,&gm,"");
printf("Enter the Radius of circle : ");
scanf("%d",&r);
x=0;
y=r;
p=1-r;
midx=getmaxx()/2; //To get the max position (Bottom-Right corner) of screen.
midy=getmaxy()/2; //Dividing by 2 to get the centre of screen.
do{
putpixel(midx+ x, midy+ y , 1); //All possible 8 combinations to draw 8 Segments
putpixel(midx- x, midy- y , 2);
putpixel(midx- x, midy+ y , 3);
putpixel(midx+ x, midy- y , 4);
putpixel(midx +y, midy+ x , 5);
putpixel(midx +y, midy -x , 6);
putpixel(midx -y, midy -x , 7);
putpixel(midx -y, midy +x , 8);
delay(20);
x++; //x will always increase , so it is incremented outside if-else
if(p<0)
{
p=p+2*x+1;
}
else
{
y--; //y decrements only when p>0
p=p+2*(x-y)+1;
}
}while(x<=y);
getch();
closegraph();
}
Last Updated: July 16, 2022
Related
IPU ECE 4th Sem Syllabus
Category: SyllabusJuly 17, 2022
BBA Digital Marketing Notes Unit 2
Category: NotesJuly 17, 2022
Nuclear Physics Notes for 1st semester
Category: NotesJuly 16, 2022
Complex Variables Handwritten
Category: NotesJuly 16, 2022
Renewable Energy Resources Unit 1
Category: NotesJuly 17, 2022
Unit 1 DC Circuits Notes
Category: NotesJuly 16, 2022
Industrial Management Akash 2015
Category: Question PapersJuly 16, 2022
Manufacturing Processes Notes (Welding and Sheet Metal)
Category: NotesJuly 16, 2022
Find greatest of two numbers in two different classes using friend function C++
Category: Practical FilesJuly 16, 2022
Java Applet Notes
Category: NotesJuly 16, 2022