Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Experiment 3: Circle Drawing using midpoint

circle algorithm

Student Name: Mohit Singh UID:19BCA1160


Branch: BCA Section/Group:2/A
Semester:5th Date of Performance:21sept2021
Subject Name :Computer Graphics Lab Subject Code:CAP-306

1) Aim: To implement midpoint circle generation algorithm for drawing a circle of given center (x, y) and
radius r.

2) Task to be done:
To implement Mid-Point Circle Algorithm for drawing a circle with x,y and radius.
Problem-01:

Given the centre point coordinates (0, 0) and radius as 10, draw a circle using mid-point circle
algorithm.

Problem-02:

Given the centre point coordinates (4, -4) and radius as 10, draw a circle using mid-point circle
algorithm.
Algorithm:
Step 1: Start.
Step 2: Declare x, y, r, x0 , y0 , error as variables, where (x0, y0) are coordinates of the center. Step 3: Put x
= 0 and y = r
Step 4: Repeat the steps while x ≤ y;
Step 5: Plot (x, y).
Step 6: if (d < 0): Set
d = d + 2x + 3 else if
(d >= 0):
Set d = d + 2(x-y) + 5
y=y-1
Step 7: Do x = x + 1
Step 8: End
3) Code for experiment/practical:

I take point coordinates(120,80) and radius as 40 because given point


coordinates display outside of output screen.
#include<iostream>
#include<graphics.h>
#include<conio.h> using
namespace std;

void drawcircle(int x0, int y0, int r)


{
int x = r;
int y = 0;
int d = 0;

while (x >= y)
{
putpixel(x0 + x, y0 + y, RED);
putpixel(x0 + y, y0 + x, RED);
putpixel(x0 - y, y0 + x, RED);
putpixel(x0 - x, y0 + y, RED);
putpixel(x0 - x, y0 - y, RED);
putpixel(x0 - y, y0 - x, RED);
putpixel(x0 + y, y0 - x, RED);
putpixel(x0 + x, y0 - y, RED);

if (d <= 0)
{
y += 1;
d += 2*y + 1;
}

if (d > 0)
{
x -= 1;
d -= 2*x + 1;
}
}
}

int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");

x=120;
y=80;
r=40;
drawcircle(x, y, r);
getch();
}

I take point coordinates(200,180) and radius as 60 because given point


coordinates display outside of output screen.

#include<iostream>
#include<graphics.h>
#include<conio.h>
void drawcircle(int x0, int y0, int r)
{
int x = r;
int y = 0;
int d = 0;
while (x >= y)
{
putpixel(x0 + x, y0 + y, RED);
putpixel(x0 + y, y0 + x, RED);
putpixel(x0 - y, y0 + x, RED);
putpixel(x0 - x, y0 + y, RED);
putpixel(x0 - x, y0 - y, RED);
putpixel(x0 - y, y0 - x, RED);
putpixel(x0 + y, y0 - x, RED);
putpixel(x0 + x, y0 - y, RED);
if (d <= 0)
{
y += 1;
d += 2*y + 1;
}
if (d > 0)
{
x -= 1;
d -= 2*x + 1;
}
}
}
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
x=200;
y=180;
r=60;
drawcircle(x, y, r);
getch();
}

4) Output

code 1
code 2

5) Learning outcomes (What I have learnt):


1.Learn about Circle Drawing using midpoint circle algorithum

2.Bresenham line algorithm is used for scan converting a line.

3. Learn about graphics

4.Learn about some methmaticals function

5: Graphics header Files

Evaluation Grid:

Sr. No. Parameters Marks Obtained Maximum Marks


1. Demonstration and 5
Performance (Pre Lab Quiz)
2. Worksheet 10
3. Post Lab Quiz 5

You might also like