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

Tuesday, 10 January 2012

Create Graphical Loading Bar in C



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

void main(void)
{
int driver=DETECT, mode;


        int i;

         initgraph(&driver,&mode,"c:\\tc\\bgi");   //initialize graphics mode
textcolor(BLACK);      //background color

        moveto(200,180);        //loading process
outtext("Loading, please wait...");
   for(i=0;i<600;i+=15)
   {
    setcolor(3);            //loading bar color
    line(20,380,i+39,380);
    delay(150);         //slow down loop speed
   }
setcolor(WHITE);
moveto(210,200);
outtext("Loading Completed!");   //loading process complete
delay(1000);
       closegraph();               //close graphics mode


}




If you have any problem with the above code, you can contact me...

Saturday, 17 December 2011

How to display a colorful animated string/phrase


#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<dos.h>      // for delay() function


void main(void)
{
    int driver=DETECT, mode;
    int i;    //for loop
    initgraph(&driver, &mode, "c:\\TC\\bgi" );
    textcolor(BLACK);
    for(i=0;i<=400;i++)
    {
    clrscr();
    setcolor(i/15);     //set text/string color
    outtextxy(20+i,150,"**C Language Codes**");  //see the description below
    delay(30);       //slow down the loop
    }
    getch();
    closegraph();
}


What is outtextxy(); ?


It is a built-in function defined in the header file "graphics.h". This function used to display graphical string. The general syntax is as follows:
outtextxy(x-coordinate, y-coordinate, "String to display"); 


In the above program, outtextxy() function is put into for loop to make the text animated. As you can see that variable i is written with the x-coordinate whereas, the y-coordinate remains constant which means the text will move towards left to right on the screen.


If you still have any question, you can ask me freely... 



Draw a colorful Circle


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

void main(void)
{
    int driver=DETECT, mode;
    int xc1=320, yc1=240;


       initgraph(&driver, &mode, "c:\\TC\\bgi" );
         setcolor(7);                     //edge color
         setfillstyle(SOLID_FILL,GREEN);  // fill inside the circle
         circle(xc1,yc1,100);             // create a circle
         floodfill(xc1,yc1,7);            // flood color
     getch();
    closegraph();
}


Output:
















If you have any question, you can ask me freely...

Friday, 18 November 2011

How to Initialize Graphics mode in C language

/*Header Files*/
#include<stdio.h>                  //for input/output purpose
#include<conio.h>                 //for getch() function
#include<graphics.h>            //for graphics functions
void main()
{
         int driver=DETECT, mode;                               //auto detect the driver
         int x=320, y=240, radius=100;                            // initialization
           initgraph(&driver , &mode , "c:\\tc\\bgi");  // all necessary graphics files in BGI folder
                  circle(x , y, radius);                                            //create a circle
         getch();                                                          // waits for key press
         closgraph();                                                    //close graphics mode
}

The above program will give the following output: