0% found this document useful (0 votes)
4 views27 pages

Computer Graphics-1

This document is a practical file for the Principles of Computer Graphics and Multimedia Applications course submitted by Navyah Vashisth as part of the Bachelor of Computer Applications degree at Panjab University. It includes an acknowledgment section and an index of various programming projects related to graphics, such as drawing shapes, animations, and plotting graphs. The document contains code snippets for each project demonstrating the application of graphics programming techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views27 pages

Computer Graphics-1

This document is a practical file for the Principles of Computer Graphics and Multimedia Applications course submitted by Navyah Vashisth as part of the Bachelor of Computer Applications degree at Panjab University. It includes an acknowledgment section and an index of various programming projects related to graphics, such as drawing shapes, animations, and plotting graphs. The document contains code snippets for each project demonstrating the application of graphics programming techniques.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

BCA-16-603

PRACTICAL FILE
Of Principles of
Computer Graphics &
Multimedia Applications

(BCA-16-603)

Submitted in partial fulfillment of the requirements of the


degree in

Bachelor of Computer Applications


(Semester 6)
(2024-25) of

Panjab University, Chandigarh

Submitted To : Submitted By :
Dr. Parminder Kaur Name -
Navyah
Vashisth
Department of Computer Science Roll No.- 247040

Khalsa College for Women, Civil Lines, Ludhiana


Navyah Vashisth
247040
BCA III
1
BCA-16-603

ACKNOWLEDGEMENT

We take immense pleasure in thanking everyone who has helped


us to conceive and develop the project. We express our heartfel
gratitude to the Principal , KHALSA COLLEGE FOR WOMEN,
LUDHIANA and the management for providing the needed.
infrastructure. We wish to express our deep sense of gratitude to
our internal guide and project leader Dr.Parminder Kaur
for their able guidance and useful. suggestions, which helped us
in completing the project work, in time, without them the project
could not have been materialized. We also thank our lab in-charge
ANIL SIR who has unconditionally helped us whenever we need
their assistance and without whom this project could not have
taken shape. Finally, yet importantly, we would like to express
our heartfelt thanks to our beloved friends/classmates for their
help and wishes for the successful completion of their project. We
thank all the people as they were the leaders and we simply
followed them

Navyah Vashisth
Roll no 247040

Navyah Vashisth
247040
BCA III
2
BCA-16-603

Index

S.no Program name Page no


1 Program to draw concentric circles using
different colours:
2 Program to fill concentric circles using different
colours
3 Program to draw and fill Indian National Flag
4 Program to draw and fill a Hut using different
patterns and colours
5 Program to draw an ellipse
6 Program to draw a Smiley face
7 Program to animate a smiling and frowning face
using cleardevice() and delay() function
8 Program to plot a Sine curve

9 Program to plot a Cosine curve


10 Program to plot a pie chart
11 Program to Plot a Bar Graph for the data input by
the user
12 Program to Plot a Line Graph for the data input by
the user
13 Move a ball horizontally across the screen using
cleardevice() and delay()
14 Move a ball vertically across the screen using
cleardevice() and delay():
15 Program to move a ball diagonally across the screen

16 To move a ball horizontally across the screen


Navyah Vashisth
247040
BCA III
3
BCA-16-603

using getimage() and putimage()


17 To move a ball vertically across the screen using
getimage() and putimage():
18 Program to simulate bouncing balls of different
colours

Navyah Vashisth
247040
BCA III
4
BCA-16-603

1 Program to draw concentric circles using different colours:

#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

2 Program to fill concentric circles using different colours

#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

3 Program to draw and fill Indian National Flag

#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

4 Program to draw and fill a Hut using different patterns and


colours

#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

5 Program to draw an ellipse

#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

6 Program to draw a Smiley face

#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

7 Program to animate a smiling and frowning face using


cleardevice() and delay() function

#include <graphics.h>
#include <conio.h>
#include <stdio.h>

void drawSmilingFace(int x, int y) {


circle(x, y, 50);
circle(x - 20, y - 20, 10);
circle(x + 20, y - 20, 10);
arc(x, y, 210, 330, 30);
}

void drawFrowningFace(int x, int y) {


circle(x, y, 50);
circle(x - 20, y - 20, 10);
circle(x + 20, y - 20, 10);
arc(x, y + 20, 30, 150, 30);
}

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");

for (int i = 0; i < 10; i++) {


cleardevice();
drawSmilingFace(300, 200);
delay(500);
cleardevice();
drawFrowningFace(300, 200);
delay(500);
}

getch();
closegraph();
}

Navyah Vashisth
247040
BCA III
11
BCA-16-603

Navyah Vashisth
247040
BCA III
12
BCA-16-603

8 Program to plot a Sine curve

#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

9 Program to plot a Cosine curve

#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

10 Program to plot a pie chart

#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");

printf("Enter the number of bars: ");


scanf("%d", &n);
int data[n];

printf("Enter the height of each bar:\n");


for (i = 0; i < n; i++) {
printf("Bar %d: ", i + 1);
scanf("%d", &data[i]);
}

for (i = 0; i < n; i++) {


height = data[i];
rectangle(x, y, x + width, y - height);
x += width + 20; // Space between bars
}

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

13 Move a ball horizontally across the screen using


cleardevice() and delay()
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,x,y,r=20;
int i=1;
initgraph(&gd,&gm,"C:\\turboc3\\bgi");
while(!kbhit())
{
x=0;
y=20;
while(x<getmaxx()-r || y<getmaxy()-r)
{
cleardevice();
setfillstyle(1,i++);
fillellipse(x,y,r,r);
x+=15;
y+=11;
delay(200);
}
}
getch();
closegraph();
}

Navyah Vashisth
247040
BCA III
21
BCA-16-603

14 Move a ball vertically across the screen using


cleardevice() and delay():

#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();
}

15 Program to move a ball diagonally across the screen

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;

while (x <= getmaxx() && y <= getmaxy()) {


cleardevice();
circle(x, y, 20);
delay(50);
x += 10;
y += 10;
}

getch();
closegraph();
}

Navyah Vashisth
247040
BCA III
23
BCA-16-603

16 To move a ball horizontally across the screen using getimage()


and putimage()

#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 = getmaxy() / 2, radius = 20, size = imagesize(x - radius, y - radius, x + radius,


y + radius);
void *ball = malloc(size);

setcolor(WHITE);
circle(x, y, radius);
floodfill(x, y, WHITE);
getimage(x - radius, y - radius, x + radius, y + radius, ball);

while (x <= getmaxx()) {


cleardevice();
putimage(x, y, ball, COPY_PUT);
delay(50);
x += 10;
}

free(ball);
getch();
closegraph();
}

Navyah Vashisth
247040
BCA III
24
BCA-16-603

17 To move a ball vertically across the screen using getimage() and


putimage():

#include <graphics.h>
#include <conio.h>
#include <stdio.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");

int x = getmaxx() / 2, y = 0, radius = 20, size = imagesize(x - radius, y - radius, x + radius,


y + radius);
void *ball = malloc(size);

setcolor(WHITE);
circle(x, y, radius);
floodfill(x, y, WHITE);
getimage(x - radius, y - radius, x + radius, y + radius, ball);

while (y <= getmaxy()) {


cleardevice();
putimage(x, y, ball, COPY_PUT);
delay(50);
y += 10;
}

free(ball);
getch();
closegraph()
}

Navyah Vashisth
247040
BCA III
25
BCA-16-603

18 Program to simulate bouncing balls of different colours

#include <graphics.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\Turboc3\\BGI");

int x = getmaxx() / 2, radius = 20;


int y[3] = {50, 100, 150};
int dy[3] = {5, 7, 9};
int colors[3] = {CYAN, YELLOW, MAGENTA};
int size = imagesize(x - radius, y[0] - radius, x + radius, y[0] + radius);
void *ball = malloc(size);

while (!kbhit()) {
cleardevice();

for (int i = 0; i < 3; i++) {


setcolor(colors[i]);
setfillstyle(SOLID_FILL, colors[i]);
circle(x, y[i], radius);
floodfill(x, y[i], colors[i]);
getimage(x - radius, y[i] - radius, x + radius, y[i] + radius, ball);
putimage(x, y[i], ball, COPY_PUT);

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

You might also like