Showing posts with label graphics in c. Show all posts
Showing posts with label graphics in c. Show all posts

Monday, 26 December 2011

Helicopter- C Graphics program

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<math.h>
#include<dos.h>
void heli();

int main()
{
    initwindow(2000,2000, "First Sample");
    heli();
    getch();
}

void heli()
    {
    int xf,yf;
    int x1,y1,x2,y2,x3,y3,x4,y4;
    int j=0,i=0;
    float t;      
    t=3.14/180;
    xf=450;
    yf=160;
    while(1)
      {
      for(i=0;i<360;i++,j++)
      {
                        setcolor(15);
                        x1=xf+(175-xf)*cos(t*i)-(150-yf)*sin(t*i);
                        y1=yf+(175-xf)*sin(t*i)+(150-yf)*cos(t*i);
                        x2=xf+(700-xf)*cos(t*i)-(150-yf)*sin(t*i);
                        y2=yf+(700-xf)*sin(t*i)+(150-yf)*cos(t*i);
                        x3=xf+(700-xf)*cos(t*i)-(175-yf)*sin(t*i);
                        y3=yf+(700-xf)*sin(t*i)+(175-yf)*cos(t*i);
                        x4=xf+(175-xf)*cos(t*i)-(175-yf)*sin(t*i);
                        y4=yf+(175-xf)*sin(t*i)+(175-yf)*cos(t*i);
                       
                       
                        line(x1+j,y1,x2+j,y2);
                        line(x2+j,y2,x3+j,y3);
                        line(x3+j,y3,x4+j,y4);
                        line(x4+j,y4,x1+j,y1);
                       
                        line(450+j,160,450+j,200);
                        line(450+j,200,250+j,215);
                        line(250+j,215,250+j,250);
                        line(250+j,225,100+j,225);
                        line(100+j,225,100+j,175);
                        line(100+j,225,100+j,235);
                        line(100+j,235,250+j,235);
                       
                       
                        line(250+j,250,425+j,300);
                        line(425+j,300,475+j,300);
                        line(450+j,300,435+j,315);
                        line(450+j,300,465+j,315);
                        line(475+j,300,650+j,250);
                       
                        line(450+j,200,650+j,215);
                        line(650+j,215,650+j,250);
                       
                       
                        setcolor(0);
                        x1=xf+(175-xf)*cos(t*i)-(150-yf)*sin(t*i);
                        y1=yf+(175-xf)*sin(t*i)+(150-yf)*cos(t*i);
                        x2=xf+(700-xf)*cos(t*i)-(150-yf)*sin(t*i);
                        y2=yf+(700-xf)*sin(t*i)+(150-yf)*cos(t*i);
                        x3=xf+(700-xf)*cos(t*i)-(175-yf)*sin(t*i);
                        y3=yf+(700-xf)*sin(t*i)+(175-yf)*cos(t*i);
                        x4=xf+(175-xf)*cos(t*i)-(175-yf)*sin(t*i);
                        y4=yf+(175-xf)*sin(t*i)+(175-yf)*cos(t*i);
                       
                        line(x1+j,y1,x2+j,y2);
                        line(x2+j,y2,x3+j,y3);
                        line(x3+j,y3,x4+j,y4);
                        line(x4+j,y4,x1+j,y1);
                       
                        line(450+j,160,450+j,200);
                        line(450+j,200,250+j,215);
                        line(250+j,215,250+j,250);
                        line(250+j,225,100+j,225);
                        line(100+j,225,100+j,175);
                        line(100+j,225,100+j,235);
                        line(100+j,235,250+j,235);
                       
                       
                        line(250+j,250,425+j,300);
                        line(425+j,300,475+j,300);
                        line(450+j,300,435+j,315);
                        line(450+j,300,465+j,315);
                        line(475+j,300,650+j,250);
                        line(450+j,200,650+j,215);
                        line(650+j,215,650+j,250);
                        }
                        }
                       
     
   
   
    
     }

Friday, 23 December 2011

Man walking on a road -C++ program

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<math.h>
void man();
int main()
{
   
    initwindow(1050,1050 , "First Sample");
    man();
   
    getch();
}
void man()
{
     float t=3.14/180,j=0.0;
     int i,p,k=0,l,x1,y1,x2,y2,xf,yf,x,y,m=0; xf=201;yf=399;
     while(1)
     {
     for(i=0,j=0;(i<70||j<45);i++,j=j+1,k++)
     {
     cleardevice();
     line(0,400,1050,400);
     line(0,600,1050,600);
     line(200+k,400,200+k,200);
     circle(200+k,170,30);
     circle(225+k,160,3);
     x=199;y=249;
     x2=x+(280-x)*sin(t*j)-(300-y)*cos(t*j);
     y2=y+(280-x)*cos(t*j)+(300-y)*sin(t*j);
     line(200+k,250,x2+k,y2);
     x1=x+(280-x)*cos(t*j)-(300-y)*sin(t*j);
     y1=y+(280-x)*sin(t*j)+(300-y)*cos(t*j);
     line(200+k,250,x1+k,y1);
     x2=xf+(280-xf)*sin(t*i)-(500-yf)*cos(t*i);
     y2=yf+(280-xf)*cos(t*i)+(500-yf)*sin(t*i);
     line(200+k,400,x2+k,y2);
     x1=xf+(280-xf)*cos(t*i)-(500-yf)*sin(t*i);
     y1=yf+(280-xf)*sin(t*i)+(500-yf)*cos(t*i);
     line(200+k,400,x1+k,y1);
     delay(3);
     }
     }
     }

Wednesday, 7 December 2011

Simple Analog Clock- C program

This is very simple program for simple clock.Here the use of cleardevice() is eliminated because cleardevice() cause blinking of screen.Several steps of program is repeated with the color black -which is similar to clearsdevice() and avoids blinking.
       

                                                                    ANALOG CLOCK


#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
void circles();
 int main()
{
    int xf,yf,x1,y1,x2,y2,k=0,x3,y3,x4,y4;
    float t,i=0.0,j=0.0;
    initwindow(1050, 1050, "First Sample");
       xf=249;
       yf=251;
       t=3.14/180;
       for(;;i=i+0.2,j=j+0.6,k=k+6)
        {
            setcolor(0);
            circles();
                
                
        x1=xf+(250-xf)*cos((i-0.2)*t)-(250-yf)*sin((i-0.2)*t);
        y1=yf+(250-xf)*sin((i-0.2)*t)+(250-yf)*cos((i-0.2)*t);
        x2=xf+(250-xf)*cos((i-0.2)*t)-(350-yf)*sin((i-0.2)*t);
        y2=yf+(250-xf)*sin((i-0.2)*t)+(350-yf)*cos((i-0.2)*t);
       
        line(x1,y1,x2,y2);
       
        x1=xf+(250-xf)*cos((j-0.6)*t)-(250-yf)*sin((j-0.6)*t);
        y1=yf+(250-xf)*sin((j-0.6)*t)+(250-yf)*cos((j-0.6)*t);
        x2=xf+(250-xf)*cos((j-0.6)*t)-(400-yf)*sin((j-0.6)*t);
        y2=yf+(250-xf)*sin((j-0.6)*t)+(400-yf)*cos((j-0.6)*t);
       
        line(x1,y1,x2,y2);
       
       
        x1=xf+(250-xf)*cos((k-6)*t)-(250-yf)*sin((k-6)*t);
        y1=yf+(250-xf)*sin((k-6)*t)+(250-yf)*cos((k-6)*t);
        x2=xf+(250-xf)*cos((k-6)*t)-(450-yf)*sin((k-6)*t);
        y2=yf+(250-xf)*sin((k-6)*t)+(450-yf)*cos((k-6)*t);
       
        line(x1,y1,x2,y2);
       
        setcolor(12);
        circles();
       
        x1=xf+(250-xf)*cos(i*t)-(250-yf)*sin(i*t);
        y1=yf+(250-xf)*sin(i*t)+(250-yf)*cos(i*t);
        x2=xf+(250-xf)*cos(i*t)-(350-yf)*sin(i*t);
        y2=yf+(250-xf)*sin(i*t)+(350-yf)*cos(i*t);
       
        line(x1,y1,x2,y2);
       
        x1=xf+(250-xf)*cos(j*t)-(250-yf)*sin(j*t);
        y1=yf+(250-xf)*sin(j*t)+(250-yf)*cos(j*t);
        x2=xf+(250-xf)*cos(j*t)-(400-yf)*sin(j*t);
        y2=yf+(250-xf)*sin(j*t)+(400-yf)*cos(j*t);
       
        line(x1,y1,x2,y2);
       
        x1=xf+(250-xf)*cos(k*t)-(250-yf)*sin(k*t);
        y1=yf+(250-xf)*sin(k*t)+(250-yf)*cos(k*t);
        x2=xf+(250-xf)*cos(k*t)-(450-yf)*sin(k*t);
        y2=yf+(250-xf)*sin(k*t)+(450-yf)*cos(k*t);
       
        line(x1,y1,x2,y2);
       delay(850);
       
       
        }
getch();
}
 void circles()
 {
                 circle(250,250,1.5);
                 circle(250,250,2);
                 circle(250,250,3);
                 circle(250,250,4);
                 circle(250,250,225);
                 circle(30,250,4);
                 circle(471,250,4);
                 circle(250,29,4);
                 circle(250,471,4);
 }   

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

Friday, 19 August 2011

Run Graphics programs in Dev C++

Many people uses Turbo c++ to run c and c++ programs. More people want to do graphics programs.If they use windows 7 64 bit they may not be able to run Turbo c++. Dev C++ is more user friendly .Here you can see how to run graphics programs in Dev C++.

Steps

1: Download graphics.h

2:Download libbgia

Download this from here .

3:Copy the graphics.h file and go to the directory C\ Dev-Cpp\include

4:paste it

5:Copy libbgia and go to C\Dev-cpp\lib

6: paste it there

7:Open Dev Cpp

8: Go to file--> New--> project

9: Go to project menu ,select project options

10: Select parameters

11: Copy the following code in the Linker field.

-lbgi
-lgdi32
-lcomdlg32
-luuid
-loleaut32
-lole32
 
11:Save this project file for future use else you should again copy the above code 
in the linker field.
 
Sample C program to draw a circle 
 
#include<stdio.h>
#include<graphics.h>
int main()
{
       initwindow(400, 300, "First Sample");
    circle(150,150,50);
getch();
}
 
Note : You can download Dev-C++ from here

Twitter Delicious Facebook Digg Stumbleupon Favorites More