You are on page 1of 3

EXP NO : 10

DATE : 02-04-2012

FLAG ANIMATION
AIM
Write a program to simulate flag animation.

ALGORITHM
1. Start
2. while key not pressed do
a. set init_angle := 0
b. draw the first sine wave with init_angle
c. draw other waves and scale up by a factor of 10
d. increment init_angle
e. if init_angle > threshold_angle then
i. reset init_angle
f. draw other connection lines and fill the flag with color
3. Stop

PROGRAM
#include<graphics.h>
#include<math.h>

void main()
{
int gd=DETECT,gm,c,i;
double x=0,y=0,x1=0,y1=0,x2=0,y2=0,x3=0,y3=0,step=M_PI/45,
xf=0,xs=0,xt=0,xl=0;
initgraph(&gd,&gm,"c:\\tc\\bgi");
while(!kbhit())
{

//first wave
moveto(300,100-y*10);
for(x=0;x<=4*M_PI;x+=step,xf+=step)

{
y=sin(xf);
lineto(300-x*15,100-y*10);
}
lineto(95,100);
//second wave
moveto(300,150-y1*10);
for(x1=0;x1<=4*M_PI;x1+=step,xs+=step)
{
y1=sin(xs);
lineto(300-x1*15,150-y1*10);
}
lineto(95,150);
//third wave
moveto(300,200-y2*10);
for(x2=0;x2<=4*M_PI;x2+=step,xt+=step)
{
y2=sin(xt);
lineto(300-x2*15,200-y2*10);
}
lineto(95,200);
//forth wave
moveto(300,250-y3*10);
for(x3=0;x3<=4*M_PI;x3+=step,xl+=step)
{
y3=sin(xl);
lineto(300-x3*15,250-y3*10);
}
lineto(95,250);
line(300,100-y*10,300,250-y3*10);
line(95,80,95,400);
setfillstyle(SOLID_FILL,LIGHTRED);
floodfill(250,125,WHITE);
setfillstyle(SOLID_FILL,WHITE);

floodfill(250,175,WHITE);
setfillstyle(SOLID_FILL,GREEN);
floodfill(250,225,WHITE);
setcolor(BLUE);
setfillstyle(SOLID_FILL,WHITE);
for(i=0;i<=360;i+=15)
pieslice(200,175-y*10,i,i+15,15);
setcolor(WHITE);
delay(10);
clearviewport();
}
closegraph();
}

OUTPUT

RESULT
The program is executed and output is verified.

You might also like