You are on page 1of 4

Q. 10 Draw Half Circle.

Bottom side

Code:
// using Bresenham’s Algorithm
#include <stdio.h>
#include <dos.h>
#include <graphics.h>

// Function to put pixels


// at subsequence points
void drawCircle(int xc, int yc, int x, int y)
{
putpixel(xc+y, yc+x, YELLOW);
putpixel(xc+x,yc+y,YELLOW);
putpixel(xc-y, yc+x, YELLOW);
putpixel(xc-x, yc+y, YELLOW);
}
// Function for circle-generation
// using Bresenham's algorithm
void circleBres(int xc, int yc, int r)
{
int x = 0, y = r;
int d = 3 - 2 * r;
drawCircle(xc, yc, x, y);
while (y >= x)
{
// for each pixel we will
// draw all eight pixels
x++;
// check for decision parameter
// and correspondingly
// update d, x, y
if (d > 0)
{
y--;
d = d + 4 * (x - y) + 10;
}
else
d = d + 4 * x + 6;
drawCircle(xc, yc, x, y);
delay(50);
}
}
int main()
{
printf("\tName : Dhiraj Kumar Sah \n");
printf("\tRoll_No: MCA/10047/19\n");
int xc = 350, yc = 350, r = 50;
int gd = DETECT, gm;
initgraph(&gd, &gm, ""); // initialize graph
circleBres(xc, yc, r); // function call
getch();
return 0;
}

Pseudo code:

Step 1:
Initialize:
xc=350
yc=350
r=50
Step 2: Call the Function circleBres (xc, yc, r)

In Function: - circleBres (xc, yc, r)


Initialize:
x=0
y=r;
Call the Function of drwamCircle (xc, yc, x, y)
we take while loop until y>=x:
x=x+1
if d>0:
y=y-1
d=d+4*(x-y) +10
else:
d=d+4*x+6;
End of While Loop
call the Function of drawCircle (xc, yc, x, y);
delay (50)
End of circleBres Function

In Function: - drawCircle (xc, yc, x, y)


putpixel (xc+y, yc+x, YELLOW);
putpixel (xc+x, yc+y, YELLOW);
putpixel (xc-y, yc+x, YELLOW);
putpixel (xc-x, yc+y, YELLOW);
End of drawCircle Function

Output:

You might also like