CG LAB(1-14)neha 1
CG LAB(1-14)neha 1
Introduction
Computer Graphics including digital images, animations, and interactive graphics used in various
sectors such as entertainment, education, scientific visualization, and virtual reality. Computer
Graphics can be used in UI design, rendering, geometric objects, animation, and many more. In
most areas, computer graphics is an abbreviation of CG.
Entertainment: Computer graphics find a major part of its utility in the movie industry
and game industry. Used for creating motion pictures, music videos, television shows,
and cartoon animation films. In the game industry where focus and interactivity are the
key players, computer graphics help in efficiently providing such features.
Education: Computer-generated models are extremely useful for teaching huge number
of concepts and fundamentals in an easy-to-understand and learn manner. Using
computer graphics many educational models can be created through which more interest
can be generated among the students regarding the subject.
Training: Specialised systems for training like simulators can be used for training the
candidates in a way that can be grasped in a short span of time with better understanding.
The creation of training modules using computer graphics is simple and very useful.
Visualization: Today the need of visualize things have increased drastically, the need of
visualization can be seen in many advanced technologies, data visualization helps in
finding insights into the data, to check and study the behavior of processes around us we
need appropriate visualization which can be achieved through proper usage of computer
graphics.
Neha Saini 220192(A2)
Machine Drawing: Computer graphics are very frequently used for designing,
modifying, and creating various parts of a machine and the whole machine itself, the
main reason behind using computer graphics for this purpose is the precision and clarity
we get from such drawing is ultimate and extremely desired for the safe manufacturing of
machine using these drawings.
Graphical User Interface: The use of pictures, images, icons, pop-up menus, and
graphical objects helps in creating a user-friendly environment where working is easy and
pleasant, using computer graphics we can create such an atmosphere where everything
can be automated and anyone can get the desired action performed in an easy fashion.
These are some of the applications of computer graphics due to which it’s popularity has
increased to a huge extend and will keep on increasing with the progress in technology
Ans: Suppose a shoe manufacturing company want to show the sale of shoes for five years. For
this vast amount of information is to store. So a lot of time and memory will be needed. This
method will be tough to understand by a common man. In this situation graphics is a better
alternative. Graphics tools are charts and graphs. Using graphs, data can be represented in
pictorial form. A picture can be understood easily just with a single look.
Interactive computer graphics work using the concept of two-way communication between
computer users. The computer will receive signals from the input device, and the picture is
modified accordingly. Picture will be changed quickly when we apply command.
Animation- A form of pictorial presentation that can enhance engagement and make
complex concepts easier to understand.
Raster scan- A rectangular pattern of image capture in television that is one of the most
popular types of graphics monitors
Neha Saini 220192(A2)
Q: Where it is used ?
Ans: Computer graphics and multimedia are used in many fields, including:
Design: Computer graphics are used in the design process for engineering and architectural
systems. For example, objects are sometimes displayed as wireframes to show their internal
features and overall shape.
Entertainment: Computer graphics and multimedia are used in the entertainment industry
for special effects in movies and animations, such as 3D animation and VFX. Multimedia
games are also popular.
Education: Computer graphics and multimedia are used in education.
Marketing: Computer graphics are used in marketing.
Healthcare: Computer graphics are used in healthcare.
Research: Computer graphics are used for simulations in research.
Electronic devices: Computer graphics are used on electronic devices to display images
Digital photography: Computer graphics are used in digital photography.
Film and television: Computer graphics are used in film and television.
Video games: Computer graphics are used in video games.
PROGRAM -1
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
Neha Saini 220192(A2)
int main() {
int gd = DETECT, gm;
closegraph();
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -2
CODE:
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
// Draw a window
rectangle(180, 330, 220, 370);
getch();
closegraph();
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -3
CODE:
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
// Draw a window
rectangle(180, 330, 220, 370);
setfillstyle(SOLID_FILL, LIGHTBLUE); // Set the fill style and color for the window
floodfill(181, 331, WHITE); // Fill the window with light blue color
getch();
closegraph();
return 0;
}
Neha Saini 220192(A2)
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -4
CODE:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -5
CODE:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
getch();
closegraph();
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -6
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
setlinestyle(0, 15, 1); // Set the line style: 0 for solid line, 15 for pattern, 1 for thickness
line(50, 50, 200, 50); // Draw a line from (50, 50) to (200, 50)
getch();
closegraph();
return 0;
}
OUTPUT:
setlinestyle(0,15,3)
setlinestyle(2,15,3)
setlinestyle(4,15,3)
Neha Saini 220192(A2)
PROGRAM -7
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
setfillstyle(1, 7); // Set the fill style to solid (1) and color to light gray (7)
floodfill(51, 51, 2); // Fill the rectangle starting from point (51, 51) with the fill color
getch();
closegraph();
return 0;
}
OUTPUT:
setfill(3,7);
Neha Saini 220192(A2)
PROGRAM -8
AIM: Write a program to implement scan conversion of a line using the Digital Differential
Analyzer (DDA) algorithm (slope <=1).
CODE:
#include <stdio.h>
#include <graphics.h>
#include <conio.h>
#include <math.h>
// Function to draw a line using the DDA (Digital Differential Analyzer) algorithm
void DDA(int x1, int y1, int x2, int y2) {
int dx = x2 - x1; // Change in x
int dy = y2 - y1; // Change in y
int steps; // Number of steps needed to draw the line
float xIncrement; // Increment in x per step
float yIncrement; // Increment in y per step
float x = x1;
float y = y1;
int main() {
int gd = DETECT;
int gm;
Neha Saini 220192(A2)
getch();
closegraph();
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -9
AIM: Write a program to implement scan conversion of a line using the Bresenham’s method
(slope <=1).
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
dx = x1 - x0;
dy = y1 - y0;
p = 2 * dy - dx; // Initial decision parameter
x = x0;
y = y0;
xEnd = x1;
if (p < 0) {
p += 2 * dy;
} else {
y++;
p += 2 * (dy - dx);
}
int main() {
int gd = DETECT;
Neha Saini 220192(A2)
int gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
getch();
closegraph();
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -10
AIM: Write a program to implement scan conversion of a line using the Bresenham’s method
(slope >1).
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
dx = x1 - x0;
dy = y1 - y0;
p = 2 * dx - dy;
x = x0;
y = y0;
xEnd = x1;
if (p > 0) {
x++;
p += 2 * (dx - dy);
}
else {
p += 2 * dx;
}
putpixel(x, y, WHITE);
}
}
int main() {
int gd = DETECT;
int gm;
Neha Saini 220192(A2)
getch();
closegraph();
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -11
AIM: Write a program to implement scan conversion of a circle using the Polynomial method.
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
int main() {
int gd = DETECT;
int gm; //
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
drawCircle(h, k, r);
getch();
closegraph();
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -12
AIM: Write a program to implement scan conversion of a circle using the Trigonometric
method.
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
int main() {
int gd = DETECT;
int gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
getch( );
closegraph( );
return 0;
}
Neha Saini 220192(A2)
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -13
AIM: Write a program to implement scan conversion of a circle using the Bresenhams method.
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
while (x < y) {
x++;
if (p < 0) {
p += 4 * x + 6;
} else {
y--;
p += 4 * (x - y) + 10;
}
int main() {
int gd = DETECT;
int gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
bresenhamCircle(h, k, r);
getch( );
closegraph( );
return 0;
}
OUTPUT:
Neha Saini 220192(A2)
PROGRAM -14
AIM: Write a program to implement scan conversion of a circle using the Mid Point method.
CODE:
#include <stdio.h>
#include <conio.h>
#include <graphics.h>
while (x < y) {
x++;
if (p < 0) {
p += 2 * x + 1;
} else {
y--;
p += 2 * (x - y) + 1;
}
int main() {
int gd = DETECT;
int gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
getch();
closegraph();
return 0;
}
OUTPUT: