Skip to main content

Bresenham's Circle Drawing Program (C++)

Bresenham's Circle Drawing C++ Program

void main() {
int gd = DETECT, gm;
initgraph (&gd, &gm, "C:\\TC\\BGI");
int xc, yc, x, y, r, D;
printf ("Enter Radius of Circle: ");
scanf ("%d", &r);
printf ("Enter coordinates of centre of Circle: ");
scanf ("%d%d", &xc, &yc);
x=0;     y=r;
D=3-(2*r);            //Initial Decision parameter
while (x<=y) {
putpixel (y+xc, x+yc, 15 );            //……octet-1
putpixel (x+xc, y+yc, 15 );            //……octet-2
putpixel (-x+xc, y+yc, 15 );          //……octet-3
putpixel (-y+xc, x+yc, 15 );          //……octet-4
putpixel (-y+xc, -x+yc, 15 );        //……octet-5
putpixel (-x+xc, -y+yc, 15 );        //……octet-6
putpixel (x+xc, -y+yc, 15 );         //……octet-7
putpixel (y+xc, -x+yc, 15 );         //……octet-8
if (D<0) {
D=D+4*x+6;         //Next Decision Parameter
else {
D=D+4*(x-y)+10;         //Next Decision Parameter
getch ();
closegraph ();


Post a Comment

Popular posts from this blog

Bresenham's Line Drawing Derivation

Bresenham's Line Drawing Algorithm Derivation
Bresenham Line drawing algorithm is used to determine closest points to be illuminated on the screen to form a line.

As we know a line is made by joining 2 points, but in a computer screen, a line is drawn by illuminating the pixels on the screen.

(Here pixel (1,2), (3,1) and (5,5) are illuminated and others are non-illuminated) A line from pixel (2,2) to (7,5) will be shown like this on the screen.

The slope of a line plays a major role in the line equation that's why Bresenham line drawing algorithm calculates the equation according to the slope of the line.

The slope of the line can be greater than 1 (m>1) or less than or equal to 1 (m<=1).
Now enough talking let's derive the equations.


Let's say we want to draw a line on the screen.
so, to draw a line we have to calculate the points or pixels to be illuminated on the screen.

Now while drawing a line a sometimes it passes through 2 pixels at the same time then we …

Computer Graphics and its Applications

We all use Computers and Mobile phones for communication all these devices have displays that show content to you but, Have you ever thought that how these displays show images and videos on screen? These images are displayed on the screens using some programming algorithms. (which we will discuss later) What is Computer Graphics?It is an art of drawing images, lines, charts, and other visuals on the computer screens with the help ofprogramming. The visuals/images on the computer screens are made up of numerous pixels. A pixel is a dot or square on the computer screen, it is the smallest unit of graphic that is displayed on the computer screen. The number of individual non-overlapping pixels contained on a computer screen is called Resolution. Now we know what is computer graphics lets know about its applications Computer Graphics ApplicationsThe Computer Graphics is used in numerous areas some of them are as follows: Graphical User Interface (GUI): The interaction of users interacts with e…

Interactive Vs Non-Interactive Graphics

There are 2 types of Computer Graphics Interactive:Here user can engage with graphics i.e. it is two way communication between user and graphics. example : video games Non-Interactive:Here user cannot engage with graphics. It is one way communication user can only watch graphical activity without any interaction. example : TV broadcasting

Interactive Graphics  Non-Interactive graphics  User interaction is required
The user has full control overthe

Bresenham's Circle Drawing Algorithm

Bresenham’s Circle Drawing Algorithm
A circle is made up of 8 Equal Octets so we need to find only coordinates of any one octet rest we can conclude using that coordinates.
We took octet-2. Where X and Y will represent the pixel Let us make a function Circle() with parameters coordinates of Centre (Xc,Yc) and pixel point (X,Y) that will plot the pixel on screen.

We will find pixels assuming that Centre is at Origin (0,0) then we will add the coordinates of centre to corresponding X and Y while drawing circle on screen.
Circle (Xc,Yc,X,Y){
Plot (Y+Xc , X+Yc)……Octet-1 Plot (X+Xc , Y+Yc)……Octet-2 Plot (-X+Xc , Y+Yc)……Octet-3 Plot (-Y+Xc , X+Yc)…..Octet-4 Plot (-Y+Xc , -X+Yc)……Octet-5