0% found this document useful (0 votes)
8 views4 pages

Jeet CG-4

The document outlines an experiment for a Computer Graphics lab where students implement two algorithms to draw a circle: the Midpoint Circle Algorithm and the Circle Generator Algorithm. It includes code snippets for both algorithms, detailing the use of graphics programming in C++. The learning outcomes emphasize understanding these algorithms, using decision parameters, and gaining practical experience in C++ graphics programming.

Uploaded by

AANAND KUMAR
Copyright
© © All Rights Reserved
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)
8 views4 pages

Jeet CG-4

The document outlines an experiment for a Computer Graphics lab where students implement two algorithms to draw a circle: the Midpoint Circle Algorithm and the Circle Generator Algorithm. It includes code snippets for both algorithms, detailing the use of graphics programming in C++. The learning outcomes emphasize understanding these algorithms, using decision parameters, and gaining practical experience in C++ graphics programming.

Uploaded by

AANAND KUMAR
Copyright
© © All Rights Reserved
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/ 4

DEPARTMENT OF

COMPUTERSCIENCE & ENGINEERING

EXPERIMENT - 4

Student Name: JEET BHARTI UID: 22BCS14804


Branch: BE-CSE Section: FL_IOT-602 ‘A’
Semester: 6th DOP: 11/02/2025
Subject: Computer Graphics LAB Subject Code: 22CSH-352

1. Aim:
a) Develop a program to draw a circle using the circle generator algorithm for a
given center and radius.
b) Develop a program to draw a circle using the midpoint circle algorithm for a
given center and radius.

2. Objective: To develop and implement the circle generator and midpoint


circle generator algorithm to draw a circle with a given center and radius.

3. Implementation/Code:

A.) Mid Point Circle Algorithm:

#include <iostream>
#include <graphics.h>
#include <cmath>

using namespace std;

void drawCircle(int xc, int yc, int r) {


for (int x = -r; x <= r; x++) {
int y = static_cast<int>(sqrt(r * r - x * x));
putpixel(xc + x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc + y, yc + x, WHITE);
putpixel(xc + y, yc - x, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc - y, yc + x, WHITE);
putpixel(xc - y, yc - x, WHITE);
}
}
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

int xc, yc, r;


cout << "Enter the center of the circle (xc, yc): ";
cin >> xc >> yc;
cout << "Enter the radius of the circle: ";
cin >> r;
DEPARTMENT OF
COMPUTERSCIENCE & ENGINEERING
drawCircle(xc, yc, r);

getch();
closegraph();
return 0;
}

B.) Circle Generator Algorithm:

#include <iostream>
#include <graphics.h>

using namespace std;

void midpointCircle(int xc, int yc, int r) {


int x = r, y = 0;
int p = 1 - r; // Initial decision parameter

// Draw the 8 symmetric points of the circle


putpixel(xc + x, yc + y, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc + y, yc + x, WHITE);
putpixel(xc - y, yc + x, WHITE);
putpixel(xc + y, yc - x, WHITE);
putpixel(xc - y, yc - x, WHITE);

// Loop until x >= y


while (x > y) {
y++;

if (p <= 0) {
p = p + 2 * y + 1; // Move to the next point in the y-direction
} else {
x--;
p = p + 2 * y - 2 * x + 1; // Move diagonally
}

// Draw the 8 symmetric points


putpixel(xc + x, yc + y, WHITE);
putpixel(xc - x, yc + y, WHITE);
putpixel(xc + x, yc - y, WHITE);
putpixel(xc - x, yc - y, WHITE);
putpixel(xc + y, yc + x, WHITE);
putpixel(xc - y, yc + x, WHITE);
putpixel(xc + y, yc - x, WHITE);
putpixel(xc - y, yc - x, WHITE);
}
}
DEPARTMENT OF
COMPUTERSCIENCE & ENGINEERING
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");

int xc, yc, r;


cout << "Enter the center of the circle (xc, yc): ";
cin >> xc >> yc;
cout << "Enter the radius of the circle: ";
cin >> r;

midpointCircle(xc, yc, r);

getch();
closegraph();
return 0;
}

4. Output:

Fig1: Mid-Point Circle Algorithm

Fig2: Circle Generator Algorithm


DEPARTMENT OF
COMPUTERSCIENCE & ENGINEERING

5. Learning Outcome:

1. Understand and implement the Midpoint Circle Algorithm and Circle Generator Algorithm
to draw a circle efficiently.
2. Learn how to use decision parameters and symmetry to plot points in a circle without using
floating-point calculations.
3. Gain hands-on experience with graphics programming in C++ using functions like putpixel
and initgraph.
4. Develop problem-solving skills by applying mathematical concepts (e.g., decision
parameters) to optimize circle drawing algorithms.

You might also like