Pages

Ads

 

Wednesday, January 1, 2014

Let us play with graphics in C | keep learning ,keep sharing

0 comments
Many times my school mates come to me an said how bore to program in C . we are getting output on black  screen ,if we are using programming languages like VB we can play with graphics .what a hell it is not in our syllabus .so this post is dedicated to them. Let us play with C.colorful texts backgrounds,shapes ,animations ,different fonts etc and create what ever you want in your own passion ,Here for compiling this program I used TURBO C++ 3.0 . for getting graphical output on your windows 7 or windows 8 you can use the following ways...
  • Use DOSBOX ,download and install it, and configure it.
  • Go to safe mode and open TURBO C++ compiler ,usually resolution will be comfortable to IDE
  • Use windows xp, in virtual box or WM ware workstation 
For implementing graphics in TURBO C++ 3.0 you have to use the header file “graphics.h” and the library file called “graphics.lib “ ,

First thing that we need to do before we can carry out any drawing activity is switch over the graphics mode . depending on the adapter and the monitor installed in your computer only some of graphics mode may available to you , display adapters are actually working in putting a picture on the screen .
To switch over to the graphics mode that offers best resolution we need to call the function initgraph() it will figure out the best resolution and puts the number corresponding to that mode in the variable “gm”, gm tells us which monitor are we are using ,and we need one more argument to this function say “gd” it is to mention device driver . Turbo C++  offers certain graphics drivers ,these are the files with extension BGI .depending upon what adapter we are using on of the adapter may get selected.

 So let us have a look on a sample program ,

 This program will change background color on each hit on any key in the keyboard
# include <stdio.h>
# include<graphics.h>
# include <conio.h>
Void main()
{
 int gd=DETECT,gm,i;
initgraph(&gd,&gm,””);
detectgraph(&gd,&gm);
for(i=0;i<=10;i++)
{
   getch();
   setbkcolor(i);
}
closegraph();
getch();



}

0 comments:

Post a Comment

 

Spam