Rotating the Fan created in last program
Rotating the Fan created in last program
We are going to Rotate the fan created in the last program.
Rotating is very easy we just follow the same steps as we done in moving Insect program.
That is we use for loop, while loop , cleardevice() and delay() function.
We have to increment the starting and ending angles.
To do this we take a variable i and initialize it under for loop that increment its values and add
this variable i in both the starting and ending angles.
Important :
Dont forget to add cleardevice() as this is used to clear the screen and avoid overlapping
of components due to the movement of them.
Program :
#include <graphics.h>
#include <conio.h>
#include <dos.h>
void main()
{
int d,m;
d = DETECT;
int midx, midy;
int i;
initgraph(&d, &m, "d:\\tc\\bgi");
midx = getmaxx() / 2;
midy = getmaxy() / 2;
while(!kbhit())
{
for(i=0;i<=40;i++)
{
if(kbhit())
{
break;
}
setfillstyle(1, 2);
pieslice(midx,midy, 180+i, 210+i,150); //Incrementing starting and ending angles by adding i
floodfill(midx,midy,15);
setfillstyle(1, 3);
pieslice(midx,midy, 110+i, 140+i,150);
floodfill(midx,midy,15);
setfillstyle(1, 4);
pieslice(midx,midy, 0+i, 30+i,150);
floodfill(midx,midy,15);
setfillstyle(1, 1);
pieslice(midx,midy, 80+i, 50+i,150);
floodfill(midx,midy,15);
setfillstyle(1, 5);
pieslice(midx,midy, 290+i, 320+i,150);
floodfill(midx,midy,15);
setfillstyle(1, 6);
pieslice(midx,midy, 235+i, 265+i,150);
floodfill(midx,midy,15);
delay(100); //to control the speed of rotation
cleardevice(); //must be put, to clear the screen
}
}
getch();
closegraph();
}
Output : You will see the following fan Rotating :
Labels:
rotating fan
Subscribe to:
Post Comments (Atom)
1 comments:
Very nice bro
Post a Comment