CGMA-Practical File
CGMA-Practical File
Of
“Graphics”
Submitted to Submitted by
Mrs.Reena Bajaj Pooja
B.C.A.(Final year)
______________________________
Master Tara Singh College For Women
Near Old Sabzi Mandi,Ludhiana.
CONTENTS
DESCRIPTION REMARKS
➢ INTRODUCTION TO GRAPHICS
➢ APPLICATIONS OF GRAPHICS
▪ PROGRAM TO DRAW A CIRCLE
▪ PROGRAM TO DRAW AN ARC
▪ PROGRAM TO DRAW AN ELLIPSE
▪ PROGRAM TO DRAW A RECTANGLE
▪ PROGRAM TO DRAW A TRIANGLE
▪ PROGRAM TO DRAW CONCENTRIC
CIRCLES
▪ PROGRAM TO DRAW JOKER WITH CAP
▪ PROGRAM TO DRAW SIN WAVES
▪ PROGRAM TO DRAW A HISTOGRAM
▪ PROGRAM TO DRAW A BAR CHART
▪ PROGRAM TO DRAW A HUT
▪ PROGRAM TO DRAW A FILLELLIPSE
▪ PROGRAM TO DRAW A SMILING FACE
▪ PROGRAM TO DRAW A SAD HUMAN FACE
▪ PROGRAM TO DRAW A CONCENTRIC
CIRCLES WITH FOR LOOP
▪ PROGRAM TO DRAW A SQUARE
▪ PROGRAM TO DRAW NUMBER OF
BALLOONS
▪ PROGRAM TO DRAW A SIN WAVE
WITH FOR LOOP
▪ PROGRAM TO DRAW A CYCLE
▪ PROGRAM TO DRAW A CAR
▪ PROGRAM TO DRAW A SCENERY
▪ PROGRAM TO DRAW A STAR
▪ PROGRAM TO DRAW DIFFERENT LINE STYLES
▪ PROGRAM TO DRAW ALL GRAPHICS
FUNCTIONS
Acknowledgement
To matter what accomplishment we achieve somebody
helps us. For every accomplishment we need the
cooperation and help of others. As knowledge advances by
steps not by leaps. So, ability advances by encouragement
and guidance. Although you have ability and knowledge
but it is worthless, unless and until you can develop it if
somebody encourage you.
About
Computer Graphics
Computer Graphics
Computer graphics studies the manipulation of visual and
geometric information using computational techniques. It is
a branch of computer science that deals with theory and
implementation of computerized image generation.
Computer graphics have been in use since the development
of computers and over the past few years, there have been
great advancement in the use of computer graphics.
Computer graphics are being used in every sphere of life
such as in science, engineering, business, medical science,
education, training and entertainment. Computer graphics
can be seen in work in film special effects, simulation and
training, TV commercial advertisements, games, animation,
medical imagery, flying logos, etc.
Computer graphics have been a key
technology ion communicating in ideas and data and
present in an interactive way. Earlier, information was
rendered in textual form only. But nowadays, it can be
displayed on the graphical devices in textual and graphical
forms for better interpretation and experience.
Computer graphics is nothing but creation,
storage, manipulation of pictures and drawing using digital
computer. It enhances the power of communication
between the computer and user. The facilities of graphics
depend upon its hardware and software.
In graphics mode the CRT screen is divided
in to a meshes of individual dots called pixels. The
measurement of pixels are called resolution of the monitor.
Applications of Computer Graphics
Computer Aided
Design:- An
important use of
computer graphics
can be seen in the
field of science and
engineering for design
applications. In recent
years, almost all
products are now
being designed using
Computer-Aided
Design (CAD) applications. CAD is the use of computer
technology to aid in the design and drawing a part or
product. It is both a visual and symbol-based method of
communication whose conventions are particular to a
specific technical field.
Of
Graphics Programs
Write a Program to draw a circle
#include<graphics>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"\\tc\\");
circle(250,250,100);
getch();
closegraph();
}
The output is:
Write a Program to draw an arc
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
arc(300,200,0,180,90);
getch();
closegraph();
}
The output is:
Write a Program to draw an ellipse
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
ellipse(300,200,0,360,50,30);
getch();
closegraph();
}
The output is:
Write a Program in graphics of rectangle
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
rectangle(100,100,300,200);
getch();
closegraph();
}
The output is:
Write a Program in graphics of triangle
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int x,y;
initgraph(&gd,&gm,"//tc//");
line(200,200,400,200);
line(200,200,300,100);
line(400,200,300,100);
getch();
closegraph();
}
The output is:
Write a Program to draw concentric circle
#include<graphics.h>
#include<conio.h>
void main()
{
int i,r=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
circle(250,200,80);
circle(250,200,70);
circle(250,200,60);
circle(250,200,50);
circle(250,200,40);
circle(250,200,30);
circle(250,200,20);
circle(250,200,10);
circle(250,200,5);
circle(250,200,0);
getch();
closegraph();
}
The output is:
Write a Program to draw a joker with cap
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int triangle[]={320,140,420,240,220,240,320,140};
initgraph(&gd,&gm,"//tc//");
drawpoly(4,triangle);
setfillstyle(5,4);
floodfill(320,150,15);
arc(320,240,180,0,100);
circle(270,270,10);
circle(370,270,10);
line(320,280,320,290);
arc(320,300,180,0,20);
setcolor(4);
fillellipse(320,295,5,4);
getch();
closegraph();
}
The output is:
Write a Program to draw a sin waves
#include<graphics.h>
#include<conio.h>
void main()
{
int i,r=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
arc(100,200,180,360,30);
arc(160,200,360,180,30);
arc(220,200,180,360,30);
arc(280,200,360,180,30);
arc(340,200,180,360,30);
arc(400,200,360,180,30);
arc(460,200,180,360,30);
getch();
closegraph();
}
The output is:
Write a Program to draw a histogram
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
line(100,400,370,400);
line(100,100,100,400);
line(130,100,130,400);
line(100,100,130,100);
line(170,150,170,400);
line(190,150,190,400);
line(170,150,190,150);
line(230,200,230,400);
line(250,200,250,400);
line(230,200,250,200);
line(290,250,290,400);
line(310,250,310,400);
line(290,250,310,250);
line(350,300,350,400);
line(370,300,370,400);
line(350,300,370,300);
getch();
closegraph();
}
The output is:
Write a Program in graphics of bar chart
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
line(100,350,310,350);
line(100,100,100,350);
line(130,100,130,350);
line(100,100,130,100);
line(130,120,160,120);
line(160,120,160,350);
line(160,140,190,140);
line(190,140,190,350);
line(190,160,220,160);
line(220,160,220,350);
line(220,180,250,180);
line(250,180,250,350);
line(250,200,280,200);
line(280,200,280,350);
line(280,220,310,220);
line(310,220,310,350);
getch();
closegraph();
}
The output is:
Write a Program in graphics of hut
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
setbkcolor(7);
setcolor(6);
line(200,120,160,200);
line(200,120,240,200);
line(200,120,390,120);
line(390,120,430,200);
line(160,200,430,200);
line(430,200,430,300);
line(160,200,160,300);
line(240,200,240,300);
line(240,300,430,300);
circle(200,170,10);
line(180,300,160,380);
line(220,300,200,380);
line(160,300,180,300);
line(220,300,240,300);
setcolor(2);
line(260,230,260,280);
line(300,230,300,280);
line(260,280,300,280);
arc(280,230,0,180,20);
line(260,230,300,230);
line(360,230,360,280);
line(400,230,400,280);
line(360,280,400,280);
arc(380,230,0,180,20);
line(360,230,400,230);
line(180,230,180,300);
line(220,230,220,300);
line(180,230,220,230);
arc(200,230,0,180,20);
getch();
closegraph();
}
The output is:
Write a Program in graphics of fillellipse
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
fillellipse(300,200,50,30);
getch();
closegraph();
}
The output is:
Write a Program in graphics of smiling
human face
#include<graphics.h>
#include<conio.h>
void main()
{
int i;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
circle(250,250,90);
circle(215,230,15);
circle(280,230,15);
line(230,280,265,280);
line(250,250,230,280);
line(250,250,265,280);
arc(250,270,190,350,40);
getch();
closegraph();
}
The output is:
Write a Program in graphics of sad human
face
#include<graphics.h>
#include<conio.h>
void main()
{
int i;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
circle(250,250,90);
circle(215,230,15);
circle(280,230,15);
fillellipse(215,250,2,1);
fillellipse(215,260,1,2);
fillellipse(280,250,2,1);
fillellipse(280,260,1,2);
line(230,280,265,280);
line(250,250,230,280);
line(250,250,265,280);
arc(250,330,20,160,40);
getch();
closegraph();
}
The output is:
Write a Program in graphics of concentric
circles with for loop
#include<graphics.h>
#include<conio.h>
void main()
{
int i,r=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
setcolor(6);
for(i=0;i<6;i++)
{
circle(300,250,r);
r+=10;
}
getch();
closegraph();
}
The output is:
Write a Program in graphics of square
#include<graphics.h>
#include<conio.h>
void main()
{
int i;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
line(100,300,300,300);
line(100,300,100,100);
line(100,100,300,100);
line(300,300,300,100);
getch();
closegraph();
}
The output is:
Write a Program in graphics of number of
balloons
#include<graphics.h>
#include<conio.h>
void main()
{
int i,r=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
ellipse(140,150,0,360,30,40);
line(140,190,250,350);
ellipse(200,120,0,360,30,50);
line(210,170,250,350);
ellipse(270,140,0,360,30,50);
line(270,190,250,350);
line(340,200,250,350);
ellipse(340,150,0,360,30,50);
arc(250,360,90,270,10);
arc(250,380,270,90,10);
line(250,390,250,440);
getch();
closegraph();
}
The output is:
Write a Program in graphics of sin wave with
for loop
#include<graphics.h>
#include<conio.h>
void main()
{
int i,x=100,y=100;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
for(i=0;i<6;i++)
{
if(i%2==0)
{
arc(x,y,0,180,30);
x=x+60;
}
else
{
arc(x,y,180,360,30);
x=x+60;
}
}
getch();
closegraph();
}
The output is:
Write a Program in graphics of cycle
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
circle(400,300,10);
circle(200,300,10);
circle(200,300,50);
circle(400,300,50);
line(200,300,400,300);
line(400,300,300,150);
line(200,300,300,150);
line(200,300,150,150);
line(150,150,300,150);
fillellipse(300,150,40,10);
arc(200,150,85,180,50);
line(400,300,400,180);
line(350,180,450,180);
getch();
closegraph();
}
The output is:
Write a Program in graphics of car
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
line(100,300,450,300);
arc(200,300,180,0,20);
arc(200,300,180,0,30);
arc(350,300,180,0,20);
arc(350,300,180,0,30);
line(100,300,100,250);
line(100,250,130,250);
line(130,250,200,170);
line(200,170,330,170);
line(420,250,330,170);
line(450,300,450,250);
line(450,250,420,250);
rectangle(400,250,420,260);
line(200,197,200,240);
line(200,240,240,240);
arc(190,240,0,60,50);
line(200,197,215,197);
line(255,197,275,197);
line(255,197,255,240);
line(300,240,255,240);
arc(250,240,0,60,50);
circle(330,220,15);
getch();
closegraph();
}
The output is:
Write a Program in graphics of scenery
#include<graphics.h>
#include<conio.h>
void main()
{
int i,r=0;
int gd=DETECT,gm;
initgraph(&gd,&gm,"//tc//");
setbkcolor(7);
setcolor(6);
line(200,120,160,200);
line(200,120,240,200);
line(200,120,390,120);
line(390,120,430,200);
line(160,200,430,200);
line(430,200,430,300);
line(160,200,160,300);
line(240,200,240,300);
line(240,300,430,300);
circle(200,170,10);
line(180,300,160,380);
line(220,300,200,380);
line(160,300,180,300);
line(220,300,240,300);
setcolor(2);
line(260,230,260,280);
line(300,230,300,280);
line(260,280,300,280);
arc(280,230,0,180,20);
line(260,230,300,230);
line(360,230,360,280);
line(400,230,400,280);
line(360,280,400,280);
arc(380,230,0,180,20);
line(360,230,400,230);
line(180,230,180,300);
line(220,230,220,300);
line(180,230,220,230);
arc(200,230,0,180,20);
arc(40,50,180,0,40);
arc(120,50,0,180,40);
arc(200,50,180,0,40);
arc(280,50,0,180,40);
arc(360,50,180,0,40);
arc(440,50,0,180,40);
arc(520,50,180,0,40);
arc(600,50,0,180,40);
arc(360,72,0,180,30);
line(342,50,320,20);
line(336,55,318,40);
line(348,46,340,30);
line(356,44,346,14);
line(363,43,365,25);
line(371,42,378,15);
line(379,47,388,30);
line(382,53,400,40);
getch();
closegraph();
}
The output is:
Write a Program in graphics of star
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"\\tc\\");
line(200,300,400,300);
line(200,300,300,140);
line(400,300,300,140);
line(200,175,400,175);
line(200,175,290,335);
line(290,335,400,175);
getch();
closegraph();
}
The output is:
Write a Program to show different line styles
#include<graphics.h>
#include<conio.h>
void main()
{
int gd =DETECT,gm;
initgraph (&gd,&gm,"//tc//");
setlinestyle(0,SOLID_LINE,1);
line(150,300,400,300);
setlinestyle(1,DOTTED_LINE,1);
line(150,350,400,300);
setlinestyle(3,DASHED_LINE,1);
line(150,400,400,300);
getche();
closegraph();
}
The output is:-