CG Exp-4
CG Exp-4
Experiment 4
Student Name: MAX UID:
Branch: CSE Section/Group:
Semester: 6th Date of Performance:
Subject Name: 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. Algorithm:
• Start
• Input center (xc, yc) and radius r.
• Set x = 0, y = r, and decision parameter p = 1 - r.
• Repeat while x ≤ y:
• Plot the points using symmetry.
• If p < 0, update p = p + 2x + 1.
• Else, update p = p + 2x - 2y + 1 and decrement y.
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
• Increment x.
• End
4. Implementation/Code:
• Circle using the Circle Generator
#include <graphics.h>
#include <cmath>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setbkcolor(GREEN);
cleardevice();
int xc = 270, yc = 240, r = 100; // Center and radius
drawCircle(xc, yc, r);
outtextxy(150,380,"Circle Using Circle Generator");
getch();
closegraph();
return 0;
DEPARTMENT OF
COMPUTER SCIENCE & ENGINEERING
}
• Circle using mid-point algorithm:
#include <graphics.h>
#include <iostream>
void drawSymmetricPoints(int xc, int yc, int x, int 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);
}
5. Output:
6. Learning Outcome:
• Learn how to use the graphics.h library for drawing basic shapes and setting up
a graphical environment in Dev-C++.
• Gain hands-on experience with two different methods: the Circle Generator
Algorithm (direct computation) and the Midpoint Circle Algorithm.
• Understood the concept of coordinating system.
• Learn about various command that is used in drawing a circle.