Computer Graphics-1
Computer Graphics-1
PRACTICAL FILE
Of Principles of
Computer Graphics &
Multimedia Applications
(BCA-16-603)
Submitted To : Submitted By :
Dr. Parminder Kaur Name -
Navyah
Vashisth
Department of Computer Science Roll No.- 247040
ACKNOWLEDGEMENT
Navyah Vashisth
Roll no 247040
Navyah Vashisth
247040
BCA III
2
BCA-16-603
Index
Navyah Vashisth
247040
BCA III
4
BCA-16-603
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int x,y;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
x=getmaxx()/2;
y=getmaxy()/2;
outtextxy(240,50,"Concentric Circle");
setcolor (RED);
circle(x,y,30);
setcolor(GREEN);
circle(x,y,50);
setcolor(YELLOW);
circle(x,y,90);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
5
BCA-16-603
#include<conio.h>
#include<graphics.h>
#include<stdio.h>
void main()
{
int gd=DETECT,gm,x,y;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
x=getmaxx()/2;
y=getmaxy()/2;
setcolor(BLUE);
setfillstyle(SOLID_FILL,BLUE);
fillellipse(x,y,100,100);
setcolor(RED);
setfillstyle(SOLID_FILL,RED);
fillellipse(x,y,80,80);
setcolor(YELLOW);
setfillstyle(SOLID_FILL,YELLOW);
fillellipse(x,y,60,60);
setcolor(GREEN);
setfillstyle(SOLID_FILL,GREEN);
fillellipse(x,y,40,40);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
6
BCA-16-603
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm,i,c=4,r=30;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
setfillstyle(1,15);
bar(100,70,110,400);
setfillstyle(1,6);
bar(100,70,225,45);
setfillstyle(1,15);
bar(100,70,225,100);
setfillstyle(1,2);
bar(100,96,225,120);
setcolor(9);
circle(160,83,13);
line(160,96,160,70);
line(147,83,173,83);
line(160,83,170,90);
line(160,83,150,92);
line(160,83,151,73);
line(160,83,170,74);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
7
BCA-16-603
#include<stdio.h>
#include<graphics.h>
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int triangle[8]={100,100,50,200,150,200,100,100};
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
setfillstyle(1,5);
bar(100,100,300,300);
setfillstyle(1,4);
drawpoly(4,&triangle[0]);
fillpoly(4,&triangle[0]);
setfillstyle(1,6);
bar(50,200,150,400);
setfillstyle(1,7);
bar(150,200,300,400);
setfillstyle(1,3);
bar(70,250,130,400);
setfillstyle(1,5);
bar(170,250,270,350);
setfillstyle(1,9);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
8
BCA-16-603
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd= DETECT, gm, x, y, start_angle=0, end_angle, x_radius, y_radius;
clrscr();
x=250, y=200, end_angle=360, x_radius=100, y_radius= 50;
initgraph(&gd, &gm, "C:\\turboc3\\bgi");
ellipse(x,y, start_angle, end_angle, x_radius, y_radius);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
9
BCA-16-603
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x=90, m=30, n=15;
clrscr();
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
setcolor(WHITE);
setfillstyle(SOLID_FILL,WHITE);
circle(150,150,x);
setcolor(YELLOW);
setfillstyle(SOLID_FILL, WHITE);
circle(65,65,m);
circle(235,65,m);
setcolor(BROWN);
setfillstyle(SOLID_FILL, WHITE);
circle(120,120,n);
circle(180,120,n);
setcolor(LIGHTRED);
arc(150,160,-180,0,50);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
10
BCA-16-603
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
11
BCA-16-603
Navyah Vashisth
247040
BCA III
12
BCA-16-603
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT, gm, xc, yc, x;
float y;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
xc=getmaxx()/2;
yc=getmaxy()/2;
line(0,yc,900,yc);
line(50,0,50,900);
line(47,yc-75,53,yc-75);
line(47,yc+80,53,yc+80);
outtextxy(55,6,"y-axis");
outtextxy(585,yc+5,"x-axis");
outtextxy(xc-200,yc+2,"o");
outtextxy(40,yc-80,"1");
outtextxy(30,yc+80,"-1");
settextstyle(3,0,2);
setcolor(65);
outtextxy(xc-30,yc-230,"Ploting Sin Graph");
for(x=0;x<=360;x++)
{
y=80*sin(x*3.14/180);
putpixel(x+50,yc-y,WHITE);
}
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
13
BCA-16-603
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
int gd=DETECT, gm, xc, yc, x;
float y;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
xc=getmaxx()/2;
yc=getmaxy()/2;
line(0,yc,900,yc);
line(50,0,50,900);
line(47,yc-75,53,yc-75);
line(47,yc+80,53,yc+80);
outtextxy(55,6,"y-axis");
outtextxy(585,yc+5,"x-axis");
outtextxy(xc-200,yc+2,"o");
outtextxy(40,yc-80,"1");
outtextxy(30,yc+80,"-1");
settextstyle(3,0,2);
setcolor(12);
outtextxy(xc-30,yc-230,"Ploting Cos Graph");
for(x=0;x<=360;x++)
{
y=80*cos(x*3.14/180);
putpixel(x+50,yc-y,WHITE);
}
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
14
BCA-16-603
Navyah Vashisth
247040
BCA III
15
BCA-16-603
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,xc,yc,i,marks[3],sum=0,sangle=0,eangle,r=50,c=1;
char sub[3][10];
float angle[3];
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
xc=getmaxx()/2;
yc=getmaxy()/2;
for(i=0;i<3;i++)
{
printf("Enter the subject and marks obtained :\n");
scanf("%s",&sub[i]);
scanf("%d",&marks[i]);
}
for(i=0;i<3;i++)
{
sum=sum+marks[i];
}
printf("Total = %d",sum);
for(i=0;i<=2;i++)
{
angle[i]=((1.0*marks[i])/sum)*360;
printf("%f",angle[i]);
}
eangle=angle[0];
for(i=0;i<=2;i++)
{
setfillstyle(1,c);
pieslice(xc,yc,sangle,eangle,r);
sangle=eangle;
if(i==2)
eangle=360;
else
eangle=sangle+angle[i+1];
c+=1;
}
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
16
BCA-16-603
Navyah Vashisth
247040
BCA III
17
BCA-16-603
11 Program to Plot a Bar Graph for the data input by the user
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
void main() {
int gd = DETECT, gm, n, i, x = 100, y = 400, width = 50, height;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
18
BCA-16-603
12 Program to Plot a Line Graph for the data input by the user
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,xc,yc,i,x1=70,y1,x2=0,y2,year[5];
long int sales[5];
long int histogram[5];
int max=0,j,k,p;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
xc=getmaxx()/2;
yc=getmaxy()/2;
for(i=0;i<5;i++)
{
printf("Enter the year and sales:\n");
scanf("%d",&year[i]);
scanf("%ld",&sales[i]);
}
cleardevice();
xc=getmaxx()/2;
xc-=269;
yc=getmaxy()/2;
line(0,yc+150,800,yc+150);
line(50,0,50,800);
for(i=0;i<5;i++)
{
outtextxy(x1,y2,"year[i]");
}
max=sales[0];
for(j=1;j<=4;j++)
{
if(sales[j]>max)
{
max=sales[j];
}
}
for(k=0;k<5;k++)
{
histogram[k]=(200*sales[k])/max;
}
putpixel(xc,yc+150,3);
x1=xc+40;
for(p=0;p<5;p++)
{
x2=x1+20;
Navyah Vashisth
247040
BCA III
19
BCA-16-603
bar(x1,(yc+150)-histogram[p],x2,(yc+150));
x1+=40;
}
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
20
BCA-16-603
Navyah Vashisth
247040
BCA III
21
BCA-16-603
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
int y = 0;
while (y <= getmaxy()) {
cleardevice();
circle(getmaxx() / 2, y, 20);
delay(50);
y += 10;
}
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
22
BCA-16-603
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
int x = 0, y = 0;
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
23
BCA-16-603
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
setcolor(WHITE);
circle(x, y, radius);
floodfill(x, y, WHITE);
getimage(x - radius, y - radius, x + radius, y + radius, ball);
free(ball);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
24
BCA-16-603
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
setcolor(WHITE);
circle(x, y, radius);
floodfill(x, y, WHITE);
getimage(x - radius, y - radius, x + radius, y + radius, ball);
free(ball);
getch();
closegraph()
}
Navyah Vashisth
247040
BCA III
25
BCA-16-603
#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");
while (!kbhit()) {
cleardevice();
y[i] += dy[i];
if (y[i] >= getmaxy() - radius || y[i] <= radius)
dy[i] = -dy[i];
}
delay(30);
}
free(ball);
getch();
closegraph();
}
Navyah Vashisth
247040
BCA III
26
BCA-16-603
Navyah Vashisth
247040
BCA III
27