73 CGA Journal
73 CGA Journal
73 CGA Journal
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
CERTIFICATE
Examiner’s Sign
Date: 22/01/2022
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Sr.
No.
Practical Date Signature
Practical 1
a. Study and enlist the basic functions used for graphics in C / C++ / Python
language. Give an example for each of them.
02/12/2021
1 b. Draw a co-ordinate axis at the centre of the screen.
2 Practical 2
a. Divide your screen into four region, draw circle, rectangle, ellipse and half
ellipse in each region with appropriate message. b. Draw a simple hut on the
08/12/2021
screen.
3 Practical 3
i. Circle ii. Rectangle iii. Square iv. Concentric Circles v. Ellipse vi. Line 08/12/2021
4 Practical 4
a. Develop the program for DDA Line drawing algorithm.
b. Develop the program for Bresenham’s Line drawing algorithm. 27/01/2022
5 Practical 5
a. Develop the program for the mid-point circle drawing algorithm.
b. Develop the program for the mid-point ellipse drawing algorithm. 02/02/2022
6 Practical 6
a. Write a program to implement 2D scaling. 07/01/2022
b. Write a program to perform 2D translation
7
Practical 7 12/01/2022
a. Perform 2D Rotation on a given object.
8 Practical 8
Write a program to implement Cohen-Sutherland clipping. 02/02/2022
9 Practical 9
a. Write a program to fill a circle using Flood Fill Algorithm. 13/01/2022
b. Write a program to fill a circle using Boundary Fill Algorithm.
10 Practical 10
a. Develop a simple text screen saver using graphics functions.
b. Perform smiling face animation using graphic functions.
c. Draw the moving car on the screen.
19/02/2022
INDEX
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 1a
AIM: - Basic Functions Used For Graphics In C / C++ / Python Language
CODE:-
#include<graphics.h>
#include<conio.h>
void main()
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); bar(50,50,150,150);
bar3d(200,50,300,150,20,1);
arc(400,100,0,130,50);
circle(600,100,50);
rectangle(200,250,450,350);
getch();
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 1b
AIM:- Draw A Co-ordinate Axis At The Center Of The Screen
CODE:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h> void
main()
{
int gd = DETECT, gm; int midx, midy; initgraph(&gd, &gm,
"C:\\TURBOC3\\BGI"); cleardevice();
midx=getmaxx()/2; midy=getmaxy()/2;
line(1,midy,1920,midy); line(midx,1,midx,1080);
getch();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 2a
AIM:- Divide Your Screen Into Four Region, Draw Circle, Rectangle, Ellipse And Half Ellipse In Each Region
CODE:-
#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
#include<graphics.h>
int main()
{
int gd,gm;
char a[2];
int x,y;
detectgraph(&gd,&gm);
x=getmaxx()/2;
y=getmaxx()/2;
line(x,0,x,y); line(0,y,x,y);
line(x,y,getmaxx(),y);
line(x,y,x,getmaxx());
outtext("Circle");
circle(159,120,80); outtextxy(320,0,"Rectangle"); rectangle(360,40,580,200); outtextxy(0,241,"Ellipse");
ellipse(159,360,0,360,50,100); outtextxy(321,241,"Half Ellipse"); ellipse(529,360,0,180,50,100); getch();
return 0; closegraph();
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 2b
AIM:- Draw A Simple Hut On The Screen
CODE:-
#include<graphics.h>
#include<conio.h>
void main()
{
int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); setcolor(WHITE);
rectangle(160,200,240,400); rectangle(185,250,215,400); rectangle(240,200,400,400);
line(160,200,200,100); line(200,100,240,200); line(200,100,350,100); line(350,100,400,200);
circle(200,170,15); getch(); closegraph();
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 3
AIM:- Draw The Basic Shapes In The Centre Of The Screen
i. Circle ii. Rectangle iii. Square iv. Concentric Circles v. Ellipse vi. Line
CODE:-
Circle in Centre of the Screen: -
#include<graphics.h>
#include<conio.h> void main()
{
int gd=DETECT,gm;
int x,y,radius=80;
initgraph(&gd,&gm,"C:\\TC\\BG I");
x=getmaxx()/2; y=getmaxy()/2;
outtextxy(x-100,50,"Circle Using Graphics in C"); circle(x,y,radius); getch();
closegrap
h();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
#include<graphics.h>
#include<conio.h> void
main()
int gd=DETECT,gm;
initgraph(&gd,&gm,"C:\\TC\\ BGI");
rectangle(150,50,400,150) ;
bar(150,200,400,350);
getch();
closegrap h();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
#include<conio.h>
void main()
{
int gd=DETECT,gm;
int x,y;
initgraph(&gd,&gm,"C:\\TC\\BGI" );
x=getmaxx()/2; y=getmaxy()/2;
outtextxy(x-100,50,"ELLIPSE Using Graphics in C");
ellipse(x,y,0,360,120,60);
getch();
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
int gd=DETECT,gm;
int x1=200,y1=200;
int x2=300,y2=300;
initgraph(&gd,&gm,"C:\\TC\\BGI" );
line(x1,y1,x2,y2);
getch();
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 4a
AIM:- Develop The Program For DDA Line Drawing Algorithm
CODE:-
#include<graphics.h>
#include<stdio.h>
#include<math.h>
#include<conio.h>
#include<dos.h>
void main()
{
float x,y,x1,y1,x2,y2,dx,dy,pixel;
int i;
int gd = DETECT, gm;
printf("Enter the value of x1");
scanf("%f",&x1); printf("Enter the value of y1"); scanf("%f",&y1); printf("Enter the value of x2");
scanf("%f",&x2); printf("Enter the value of y2"); scanf("%f",&y2); initgraph(&gd, &gm, "C:\\TURBOC3\\
BGI"); dx=abs(x2-x1); dy=abs(y2y1); if(dx>=dy) pixel=dx; else pixel=dy; dx=dx/pixel; dy=dy/pixel; x=x1; y=y1;
i=1; while(i<=pixel)
{
putpixel(x,y,3); //putpixel(int x, int y, int color) x=x+dx; y=y+dy;
i=i+1; delay(100);
}
getch(); closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 4b
AIM:- Develop The Program For Bresenham’s Line Drawing Algorithm
CODE:-
#include<iostream.h>
#include<graphics.h>
dx=x1-x0;
dy=y1-y0;
return 0;
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 5a
AIM:- Develop The Program For The Mid-point Circle Drawing Algorithm
CODE:-
#include<iostream.h>
#include<graphics.h>
#include<conio.h> #include<math.h> void main()
{ clrscr(); int r,d,x,y,gd,gm,a,b; cout<<"enter the radius "<<endl; cin>>r; cout<<"enter the center"<<endl;
cin>>a>>b; x=0; y=r;
detectgraph(&gd,&gm); initgraph(&gd,&gm,"C:\\TC\\BGI")
; d=1.25-r; do
{
putpixel(200+x,200+y,RED); putpixel(200+y,200+x,GREEN); putpixel(200+y,200x,BLUE);
putpixel(200+x,200-y,RED); putpixel(200x,200-y,BLUE); putpixel(200-y,200-x,RED);
putpixel(200-y,200+x,YELLOW); putpixel(200x,200+y,RED); putpixel(200+a,200+b,GREEN);
putpixel(200+b,200+a,RED); putpixel(200+b,200a,WHITE); putpixel(200+a,200-b,RED);
putpixel(200a,200-b,WHITE); putpixel(200-b,200-a,RED); putpixel(200-b,200+a,BLUE);
putpixel(200a,200+b,RED);
if (d<0)
{
x=x+1;
y=y;
d=d+2*x+1;
} else
{
x=x+1; y=y-1; d=d+2*(x-
y)+1;
}
} while(x<y); getch();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 5b
AIM:- Develop The Program For The Mid-point Ellipse Drawing Algorithm
CODE:-
#include<graphics.h>
#include<stdlib.h>
#include<iostream.h> #include<conio.h> void main()
{ clrscr(); int gd = DETECT, gm; int xc,yc,x,y;float p; long rx,ry; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
cout<<"Enter coordinates of centre : "; cin>>xc>>yc; cout<<"Enter x,y radius of ellipse: "; cin>>rx>>ry;
} else
{
x++;y--;
p = p+2*ry*ry*x-2*rx*rx*y-ry*ry;
}
putpixel(xc+x,yc+y,YELLOW); putpixel(xc+x,yc-y,YELLOW); putpixel(xc-x,yc+y,YELLOW);
putpixel(xc-x,yc-y,YELLOW);
}
//Region 2 p=ry*ry*(x+0.5)*(x+0.5)+rx*rx*(y-1)*(y-1)-
rx*rx*ry*ry; while(y > 0)
{
if(p <= 0)
{
x++;y--;
p = p+2*ry*ry*x-2*rx*rx*y+rx*rx;
} else
{
y--;
p = p-2*rx*rx*y+rx*rx;
}
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 6a
AIM:- Write A Program To Implement 2D Scaling
CODE:-
#include<graphics.h>
#include<stdio.h> #include<conio.h> void main()
{
int x,y,x1,y1,x2,y2; int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); printf("Enter two line
points:
x1,y1,x2,y2:\n");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2); printf("\nLine before scaling"); line(x1,y1,x2,y2);
printf("\nEnter scaling factors: x,y\n"); scanf("%d%d",&x,&y); x1=(x1*x); y1=(y1*y); x2=(x2*x); y2=(y2*y);
printf("\n\n\nLine after scaling"); line(x1,y1,x2,y2); getch(); closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 6b
AIM:- Write A Program To Perform 2D Translation
CODE:-
#include<graphics.h>
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,x1,y1,x2,y2; int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\TURBOC3\\BGI"); printf("Enter two line
points:
x1,y1,x2,y2:\n"); scanf("%d%d%d%d",&x1,&y1,&x2,&y2); printf("\nLine before translation");
line(x1,y1,x2,y2);
printf("\nEnter translation factors: x,y\n"); scanf("%d%d",&x,&y); x1=(x1+x); y1=(y1+y); x2=(x2+x);
y2=(y2+y); printf("\n\n\nLine after translation"); line(x1,y1,x2,y2); getch(); closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 7a
AIM:- Perform 2D Rotation On A Given Object
CODE:-
#include <math.h>
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
void main()
{
int gd=DETECT,gm,x1,x2,y1,y2,x3,y3,x4,y4;
initgraph(&gd,&gm,"C:\\Turboc3\\BGI");
float angle=0,ang; cout<<"\nROTATION OF A LINE\n"; cout<<"Enter the first coordinate of a
line:"; cin>>x1>>y1; cout<<"Enter the second coordinate of a line:"; cin>>x2>>y2;
line(x1,y1,x2,y2);
cout<<"Enter the angle:"; cin>>ang; angle=(ang*3.14)/180; setcolor(YELLOW);
cout<<"\nClockwise Rotation\n";
x3=x2-(((x2-x1)*cos(angle))-((y2-y1)*sin(angle))); y3=y2-(((x2-x1)*sin(angle))+((y2-
y1)*cos(angle))); cout<<"\nAnti-clockwise Rotation"; x4=x2-(((x2x1)*cos(angle))+((y2-
y1)*sin(angle))); y4=y2-(((x2-x1)*sin(angle))+((y2-y1)*cos(angle))); line(x2,y2,x3,y3);
line(x2,y2,x4,y4);
getch();
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 7b
AIM:- Create A House
CODE:-
#include <conio.h>
#include <graphics.h>
#include <stdio.h> // Driver Code void main()
{
int gd =DETECT,gm;
int gdriver = DETECT, gmode; initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
line(100, 100, 150, 50); line(150, 50, 200, 100);
line(150, 50, 350, 50); line(350, 50, 400, 100);
rectangle(100, 100, 200, 200);
rectangle(200, 100, 400, 200);
rectangle(130, 130, 170, 200);
rectangle(250, 120, 350, 180);
setfillstyle(2, 3);
floodfill(131, 131, WHITE);
floodfill(201, 101, WHITE);
setfillstyle(11, 7);
floodfill(101, 101, WHITE);
floodfill(150, 52, WHITE);
floodfill(163, 55, WHITE);
floodfill(251, 121, WHITE);
getch();
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 8a
AIM:- Write A Program To Implement Cohen-Sutherland Clipping
CODE:-
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gd=DETECT, gm; float i,xmax,ymax,xmin,ymin,x1,y1,x2,y2,m;
float start[4],end[4],code[4];
clrscr();
initgraph(&gd,&gm,"C:\\TURBOC3\\BGI");
printf("\n\tPlease enter the bottom left co-ordinate of viewport: ");
scanf("%f %f",&xmin,&ymin); printf("\n\tPlease enter the top right coordinate of viewport: ");
scanf("%f %f",&xmax,&ymax); printf("\nPlease enter the co-ordinates for starting point of line: ");
scanf("%f %f",&x1,&y1);
printf("\nPlease enter the co-ordinates for ending point of line: ");
scanf("%f %f",&x2,&y2);
for(i=0;i <4;i++)
{
start[i]=0; end[i]=0;
}
m=(y2-y1)/(x2-x1);
if(x1 <xmin) start[0]=1;
if(x1>xmax) start[1]=1;
if(y1 >ymax) start[2]=1;
if(y1<ymin) start[3]=1;
if(x2 <xmin) end[0]=1;
if(x2 >xmax) end[1]=1;
if(y2 >ymax) end[2]=1;
if(y2 <ymin) end[3]=1;
for(i=0;i <4;i++) code[i]=start[i]&&end[i];
if((code[0]==0)&&(code
[1]==0)&&(code[2]==0)
&&(code[3]==0))
{
if((start[0]==0)&&(start[1]==0)&&(start[2]==0)&&(start[3]==0)&&(end[0]==0)&&(end[1]==0)&&(end[2]==0)
&&(end[3]==0)
)
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
{
cleardevice();
printf("\n\t\tThe line is totally visible\n\t\tand not a clipping candidate");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
getch();
}
else
{
cleardevice();
printf("\n\t\tLine is partially visible");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2);
getch();
if((start[2]==0)&&(start[3]==1))
{
x1=x1+(ymin-y1)/m; y1=ymin;
}
if((end[2]==0)&&(end[3]==1))
{
x2=x2+(ymin-y2)/m; y2=ymin;
}
if((start[2]==1)&&(start[3]==0))
{
x1=x1+(ymax-y1)/m; y1=ymax;
}
if((end[2]==1)&&(end[3]==0))
{
x2=x2+(ymax-y2)/m; y2=ymax;
}
if((start[1]==0)&&(start[0]==1))
{
y1=y1+m*(xmin-x1); x1=xmin;
}
if((end[1]==0)&&(end[0]==1))
{
y2=y2+m*(xmin-x2); x2=xmin;
} if((start[1]==1)&&(start[0]==0))
{
y1=y1+m*(xmax-x1); x1=xmax;
}
if((end[1]==1)&&(end[0]==0))
{
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
y2=y2+m*(xmax-x2); x2=xmax;
}
clrscr();
cleardevice();
printf("\n\t\tAfter clippling:");
rectangle(xmin,ymin,xmax,ymax);
line(x1,y1,x2,y2); getch();
}
}
else
{
clrscr();
clearde vice();
printf(" \nLine is invisibl e");
rectangle(xmin ,ymin,x max,ymax);
}
getch();
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 8b
AIM:- Write A Program To Implement Liang - Barsky Line Clipping Algorithm
CODE:-
#include<iostream.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
void main()
{
int i,gd=DETECT,gm; int x1,y1,x2,y2,xmin,xmax,ymin,ymax,xx1,xx2,yy1,yy2,dx,dy; float
t1,t2,p[4],q[4],temp; x1=120; y1=120; x2=300; y2=300; xmin=100; ymin=100; xmax=250;
ymax=250; initgraph(&gd,&gm,"c:\\turboc3\\bgi"); rectangle(xmin,ymin,xmax,ymax); dx=x2-x1;
dy=y2-y1; p[0]=-dx; p[1]=dx; p[2]=-dy; p[3]=dy; q[0]=x1-xmin; q[1]=xmax-x1; q[2]=y1-ymin;
q[3]=ymax-y1;
for(i=0;i<4;i++)
{
if(p[i]==0)
{
cout<<"line is parallel to one of the clipping boundary"; if(q[i]>=0)
{ if(i<2)
{
if(y1<ymin)
{
y1=ymin;
}
if(y2>ymax)
{
y2=ymax;
}
line(x1,y1,x2,y2);
} if(i>1)
{
if(x1<xmin)
{
x1=xmin;
}
if(x2>xmax)
{
x2=xmax;
}
line(x1,y1,x2,y2);
}
}
}
}
t1=0; t2=1;
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
for(i=0;i<4;i++)
{
temp=q[i]/p[i]; if(p[i]<0)
{
if(t1<=temp) t1=temp;
} else
{
if(t2>temp) t2=temp;
}
}
if(t1<t2)
{
xx1 = x1 + t1 * p[1]; xx2 = x1 + t2 * p[1]; yy1 = y1 + t1 * p[3]; yy2 = y1 + t2 * p[3];
line(xx1,yy1,xx2,yy2);
}
delay(5000);
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 9a
AIM:- Write A Program To Fill A Circle Using Flood Fill Algorithm
CODE:-
#include<stdio.h>
#include<graphics.h>
#include<dos.h>
void floodFill(int x,int y,int oldcolor,int newcolor)
{
if(getpixel(x,y) == oldcolor)
{
putpixel(x,y,newcolor); floodFill(x+1,y,oldcolor,newcolor);
floodFill(x,y+1,oldcolor,newcolor); floodFill(x-
1,y,oldcolor,newcolor); floodFill(x,y-
1,oldcolor,newcolor);
}
}
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 9b
AIM:- Write A Program To Fill A Circle Using Boundary Fill Algorithm
CODE:-
#include<iostream.h>
#include<graphics.h>
#include<dos.h>
void boundaryfill(int x,int y,int f_color,int b_color)
{
if(getpixel(x,y)!=b_color && getpixel(x,y)!=f_color)
{
putpixel(x,y,f_color); boundaryfill(x+1,y,f_color,b_color);
boundaryfill(x,y+1,f_color,b_color); boundaryfill(x-1,y,f_color,b_color);
boundaryfill(x,y1,f_color,b_color);
}
}
//getpixel(x,y) gives the color of specified pixel
int main()
{
int gm,gd=DETECT,radius;
int x,y; cout<<"Enter x and y positions for circle\n";
cin>>x>>y; cout<<"Enter radius of circle\n"; cin>>radius; initgraph(&gd,&gm,"c:\\turboc3\\
bgi"); circle(x,y,radius); boundaryfill(x,y,4,15); delay(5000); closegraph();
return 0;
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 10a
AIM:- Develop A Simple Text Screen Saver Using Graphics Functions
CODE:-
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
void main()
{
int gm,gd=DETECT,x=600;
int i;
initgraph(&gd,&gm,"c:\\turboc3\\bg i");
for(x=0;x<250;x++)
{
x%=250;
//setcolor(random(16));
//circle(random(635),random(70),50);
clearviewport();
settextstyle(1,0,5);
setcolor(YELLOW);
outtextxy(50,415-2*x,"*WORLD*");
setcolor(GREEN);
outtextxy(250,415-2*x,"*OF*");
setcolor(RED);
settextstyle(3,0,5);
outtextxy(350,415- 2*x,"*GRAPHICS*");
}
getch();
closegraph();
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 10b
AIM:- Perform Smiling Face Animation Using Graphic Functions
CODE:-
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <stdio.h>
int main()
{
int gr = DETECT, gm;
initgraph(&gr, &gm, "C:\\Turboc3\\BGI");
setcolor(YELLOW); circle(300, 100, 40);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(300, 100, YELLOW);
setcolor(BLACK);
setfillstyle(SOLID_FILL, BLACK);
fillellipse(310, 85, 2, 6);
fillellipse(290, 85, 2, 6);
ellipse(300, 100, 205, 335, 20, 9);
ellipse(300, 100, 205, 335, 20, 10);
ellipse(300, 100, 205, 335, 20, 11);
getch();
closegraph();
return 0;
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
Practical 10c
AIM:- Draw The Moving Car On The Screen
CODE:-
#include<graphics.h>
#include<conio.h>
int main()
{
intgd=DETECT,gm, i, maxx, cy;
initgraph(&gd, &gm, "C:\\TC\\BGI");
setbkcolor(WHITE);
setcolor(RED);
maxx = getmaxx(); cy = getmaxy()/2;
for(i=0;i<maxx-140;i++)
{
cleardevice();
line(0+i,cy-20, 0+i, cy+15); line(0+i, cy-20, 25+i, cy-20); line(25+i, cy20, 40+i, cy-70); line(40+i, cy-70,
100+i, cy-70); line(100+i, cy-70, 115+i, cy20); line(115+i, cy-20, 140+i, cy-20); line(0+i, cy+15, 18+i,
cy+15); circle(28+i, cy+15, 10); line(38+i, cy+15, 102+i, cy+15); circle(112+i, cy+15,10); line(122+i,
cy+15 ,140+i,cy+15); line(140+i, cy+15, 140+i, cy-20); rectangle(50+i, cy-62, 90+i, cy-30);
setfillstyle(1,BLUE); floodfill(5+i, cy-15, RED); setfillstyle(1, LIGHTBLUE); floodfill(52+i, cy-60, RED);
delay(10);
}
getch();
closegraph();
return 0;
}
OUTPUT:-
35 SADIYA SHAIKH
SEM IV COMPUTER GRAPHICS AND ANIMATION SYBSCIT
35 SADIYA SHAIKH