Aug 19, 2011 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. /little-snitch-3-mac-download.html. Dev C is more user friendly.Here you can see how to run graphics programs in Dev C. Oct 05, 2014 General C Programming; Can't be able to use 'graphics.h' in Cod. Can't be able to use 'graphics.h' in Code Block? I'm trying to use 'graphics.h' just for learning purpose. (That creates a graphics window you can draw a line in, in contrast to a fullscreen graphics mode.) Take a look at the first example to see how create a.
Graphics programming in C used to drawing various geometrical shapes(rectangle, circle eclipse etc), use of mathematical function in drawing curves, coloring an object with different colors and patterns and simple animation programs like jumping ball and moving cars.
The first step in any graphics program is to include
graphics.h header file. The
graphics.h header file provides access to a simple graphics library that makes it possible to draw lines, rectangles, ovals, arcs, polygons, images, and strings on a graphical window.
The second step is initialize the graphics drivers on the computer using
initgraph method of
It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode. It also resets or initializes all graphics settings like color, palette, current position etc, to their default values. Below is the description of input parameters of initgraph function.
graphicsDriver : It is a pointer to an integer specifying the graphics driver to be used. It tells the compiler that what graphics driver to use or to automatically detect the drive. In all our programs we will use
DETECT macro of graphics.h library that instruct compiler for auto detection of graphics driver.
graphicsMode : It is a pointer to an integer that specifies the graphics mode to be used. If
*gdriver is set to
*gmode to the highest resolution available for the detected driver.
driverDirectoryPath : It specifies the directory path where graphics driver files (
BGI files) are located. If directory path is not provided, then it will search for driver files in current working directory directory. In all our sample graphics programs, you have to change path of BGI directory accordingly where you Turbo C++ compiler is installed.
We have declared variables so that we can keep track of starting and ending point.
No, We need to pass just 4 parameters to the
line Function Draws Line From (x1,y1) to (x2,y2) .
At the end of our graphics program, we have to unloads the graphics drivers and sets the screen back to text mode by calling
There are 16 colors declared in graphics.h header file. We use colors to set the current drawing color, change the color of background, change the color of text, to color a closed shape etc (Foreground and Background Color). To specify a color, we can either use color constants like setcolor(RED), or their corresponding integer codes like setcolor(4). Below is the color code in increasing order.
***** To display blinking characters in text mode, add BLINK to the foreground color. (Defined in
|Example Statement for Graphics in C Language|
|1. Drawing Line in Graphics Mode|
|2. Make Static Countdown|
|3. Draw Moving a Car|
|4. Press Me Button Game|
|5. Draw Smiling Face Animation|
|6. Make Traffic Light Simulation|