Tuesday 6 December 2011

Simple Fan implementation-C program

This is simple program that implements a fan.
It just gives an idea,you can modify by filling color  and additional  drawings etc.
This graphics progam is written  in Dev C++ so it needs slight modifications to  run in Turbo C++ or C etc.



                                                                    FAN
                 


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

void fan(int );

int main()
{
    initwindow(500, 500, "First Sample");
    fan(100);
    getch();
}

void fan(int p)
    {
    int xf,yf;
    int x1,y1,x2,y2,x3,y3,x4,y4;
    int j=0,i;
    float t;
      
       setcolor(12);
       xf=150;                        //Center of circle
       yf=150;
       t=3.14/180;
       while(j==0 )
           {   
                    for(;;i++)
       {
           cleardevice();
           circle(150,150,25);
           circle(150,150,1);
           line(150,126,150,100);
          
       x1=xf+(175-xf)*cos(120*t+i)-(130-yf)*sin(120*t+i);
       y1=yf+(175-xf)*sin(120*t+i)+(130-yf)*cos(120*t+i);
       x2=xf+(275-xf)*cos(120*t+i)-(130-yf)*sin(120*t+i);
       y2=yf+(275-xf)*sin(120*t+i)+(130-yf)*cos(120*t+i);
       x3=xf+(175-xf)*cos(120*t+i)-(150-yf)*sin(120*t+i);
       y3=yf+(175-xf)*sin(120*t+i)+(150-yf)*cos(120*t+i);
       x4=xf+(275-xf)*cos(120*t+i)-(150-yf)*sin(120*t+i);
       y4=yf+(275-xf)*sin(120*t+i)+(150-yf)*cos(120*t+i);
                         line(x1,y1,x2,y2);
                         line(x2,y2,x4,y4);
                         line(x4,y4,x3,y3);
                         line(x3,y3,x1,y1);
       x1=xf+(175-xf)*cos(240*t+i)-(130-yf)*sin(240*t+i);
       y1=yf+(175-xf)*sin(240*t+i)+(130-yf)*cos(240*t+i);
       x2=xf+(275-xf)*cos(240*t+i)-(130-yf)*sin(240*t+i);
       y2=yf+(275-xf)*sin(240*t+i)+(130-yf)*cos(240*t+i);
       x3=xf+(175-xf)*cos(240*t+i)-(150-yf)*sin(240*t+i);
       y3=yf+(175-xf)*sin(240*t+i)+(150-yf)*cos(240*t+i);
       x4=xf+(275-xf)*cos(240*t+i)-(150-yf)*sin(240*t+i);
       y4=yf+(275-xf)*sin(240*t+i)+(150-yf)*cos(240*t+i);
                         line(x1,y1,x2,y2);
                         line(x2,y2,x4,y4);
                         line(x4,y4,x3,y3);
                         line(x3,y3,x1,y1);
       x1=xf+(175-xf)*cos(360*t+i)-(130-yf)*sin(360*t+i);
       y1=yf+(175-xf)*sin(360*t+i)+(130-yf)*cos(360*t+i);
       x2=xf+(275-xf)*cos(360*t+i)-(130-yf)*sin(360*t+i);
       y2=yf+(275-xf)*sin(360*t+i)+(130-yf)*cos(360*t+i);
       x4=xf+(175-xf)*cos(360*t+i)-(150-yf)*sin(360*t+i);
       y4=yf+(175-xf)*sin(360*t+i)+(150-yf)*cos(360*t+i);
       x3=xf+(275-xf)*cos(360*t+i)-(150-yf)*sin(360*t+i);
       y3=yf+(275-xf)*sin(360*t+i)+(150-yf)*cos(360*t+i);
                         line(x1,y1,x2,y2);
                         line(x2,y2,x3,y3);
                         line(x3,y3,x4,y4);
                         line(x4,y4,x1,y1);
       delay(p);
    }
    }
    }

0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More