0% found this document useful (0 votes)
18 views6 pages

CG 4

The document outlines two experiments in a Computer Graphics course focused on drawing circles using different algorithms: the Circle Generator Algorithm and the Midpoint Circle Algorithm. Each experiment includes the aim, objectives, algorithms, implementation code in C++, and learning outcomes related to graphics programming. The experiments aim to enhance understanding of circle drawing techniques and improve skills in using graphics libraries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views6 pages

CG 4

The document outlines two experiments in a Computer Graphics course focused on drawing circles using different algorithms: the Circle Generator Algorithm and the Midpoint Circle Algorithm. Each experiment includes the aim, objectives, algorithms, implementation code in C++, and learning outcomes related to graphics programming. The experiments aim to enhance understanding of circle drawing techniques and improve skills in using graphics libraries.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DEPARTMENT OF

COMPUTER SCIENCE &


ENGINEERING
Experiment 4(A)

Student Name: Prince Kumar Singh UID: 22BCS11746


Branch: BE-CSE Section/Group:
612/A
Semester: 6 Date of
Performance:13/02/25 Subject Name: Computer Graphics Subject
Code:22CSH-352
with lab

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

2. Objective: To develop and implement the circle generator algorithm to draw a circle with a
given center and radius.

3. Algorithm:
• Initialize Graphics Mode: Detect the graphics driver and initialize the graphics mode.
• Input Values: Take user input for the center (xc, yc) and radius r of the circle.
• Plot Circle Points:
a) Use a loop from theta = 0 to 360 degrees.
b) Convert theta to radians and compute x and y using trigonometric functions.
c) Plot each point using putpixel(x, y, WHITE).
• Wait for User Input: Use getch() to pause execution.
• Close Graphics Mode: Terminate the graphics session.

4. Implementation/Code:
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <iostream.h>

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


1
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");

for (float theta = 0; theta <= 360; theta += 0.1) {


int x = xc + r * cos(theta * 3.14159 / 180);
int y = yc + r * sin(theta * 3.14159 / 180);
putpixel(x, y, WHITE);
}

getch();
closegraph();
}

int main() {
int xc, yc, r;
cout << "PRINCE KUMAR SINGH" << endl;
cout << "22BCS11746" << endl;

cout << "Enter center (xc, yc): ";


cin >> xc >> yc;
cout << "Enter radius: ";
cin >> r;

drawCircle(xc, yc, r);


return 0;
}
5. Output:

6. Learning Outcomes:
2
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
 Understand the implementation of the circle generation algorithm using parametric equations.
 Develop skills in graphics programming using C++ with the <graphics.h> library.
 Gain hands-on experience in plotting points based on trigonometric functions for drawing a circle.

3
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
Experiment 4(B)

1. Aim: 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 midpoint circle algorithm to draw a circle with a
given center and radius.

3. Algorithm:
a. Initialize Variables
1. Set the center of the circle (xc, yc).
2. Initialize starting point (x = 0, y = r).
3. Compute initial decision parameter p = 1 - r.
b. Plot Initial Points
1. Use 8-way symmetry to plot the first set of points using putpixel().
c. Iterate Until x <= y
1. Increment x.
2. Update decision parameter p:
a) If p < 0, update p as p = p + 2x + 1.
b) Otherwise, decrement y and update p as p = p + 2(x - y) + 1.
3. Plot the new points in all 8 symmetrical positions.
d. Exit Loop and Close Graphics

4. Implementation/Code:
#include <graphics.h>
#include <conio.h>
#include <iostream.h>

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


int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");

int x = 0, y = r;
int d = 1 - r;

while (x <= y) {
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);
4
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
x++;
if (d < 0)
d += 2 * x + 1;
else {
y--;
d += 2 * (x - y) + 1;
}
}

getch();
closegraph();
}

int main() {
int xc, yc, r;
cout << "PRINCE KUMAR SINGH" << endl;
cout << "22BCS11746" << endl;

cout << "Enter center (xc, yc): ";


cin >> xc >> yc;
cout<<"Enter radius: ";
cin>>r;

drawCircle(xc,yc,r);
return 0;
}
5. Output:

5
DEPARTMENT OF
COMPUTER SCIENCE &
ENGINEERING
6. Learning Outcome:
a. Understand the implementation of the Midpoint Circle Algorithm for efficient circle
drawing.
b. Develop skills in decision-based pixel plotting to minimize computations in graphics
programming.
c. Gain hands-on experience in optimizing circle drawing using symmetry and incremental
calculations.

You might also like