Showing posts with label dev cpp. Show all posts
Showing posts with label dev cpp. Show all posts

Friday, 23 December 2011

Vehicles moving on road- C graphics program

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
#include<dos.h>
 int main()
{
    int i,j,k,l,m,n,p;
    initwindow(600, 400, "First Sample");

  line(0,160,700,160);
  line(0,275,700,275);
    for(i=0,j=500;i<500;i=i+2,j=j-3)
    {               
                     setcolor(15);
                      rectangle(25+j,225,75+j,245);
                      line(25+j,235,75+j,235);
                      circle(38+j,250,5);
                      circle(68+j,250,5);
                      delay(5);
                      setcolor(0);
                      rectangle(25+j,225,75+j,245);
                      line(25+j,235,75+j,235);
                      circle(38+j,250,5);
                      circle(68+j,250,5);
                      setcolor(15);
                      rectangle(25+i,165,75+i,200);
                      rectangle(75+i,175,85+i,200);
                      circle(38+i,205,5);
                      circle(68+i,205,5);
                      delay(5);
                      setcolor(0);
                      rectangle(25+i,165,75+i,200);
                      rectangle(75+i,175,85+i,200);
                      circle(38+i,205,5);
                      circle(68+i,205,5);
                      }
                      setcolor(15);
                      rectangle(25+i,165,75+i,200);
                      rectangle(75+i,175,85+i,200);
                      circle(38+i,205,5);
                      circle(68+i,205,5);
 getch();
}

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