C programming graphics


0  0 2017-01-18 09:31:39

Graphics programming in C is easy and it’s interesting. One can use graphics programming for developing your games, for animation etc. It is not like traditional C programming in which you have to apply logic in your program and then to end up with lots of errors and warnings in program. You have to use standard library functions to complete the tasks in C graphics programming. You just need pass arguments to functions. Firstly you are supposed to know the function initgraph which is used to initialize graphics mode. To initialize graphics mode we use initgraph function in program. initgraph function present in "graphics.h" which is header file, any of the graphics program in C should include "graphics.h" header file.
Below is the example of initgraph:

Sample graphics code
#include<graphics.h>   //Header file
#include<conio.h>        //Header file
int main()
    int ge = DETECT, ga;
    initgraph(&ge, &ga, "C:\\TC\\BGI");
       return 0;

Some Functions of graphics.h
Syntax :- void arc(int x, int y, int startangle, int endangle, int radius);
This function is used to draw  arc with center (x,y) and startangle (Start Angle), endangle (End Angle) and last parameter (radius of arc). This function can also used to draw circle but for that starting angle and end angle should be 0 and 360.

2. Bar
Syntax :- void bar(int left, int top, int right, int bottom);
This function is used to draw 2-dimensional, rectangular filled in bar . Coordinates of left top and right bottom corner are required to draw the bar. Left specifies the X-coordinate of top left corner, top specifies the Y-coordinate of top left corner, right specifies the X-coordinate of right bottom corner, bottom specifies the Y-coordinate of right bottom corner. Current fill pattern and fill color is used to fill the bar. To change fill pattern and fill color use setfillstyle.

3. Circle
Syntax :- void circle(int x, int y, int radius);
The Circle function is used to draw circle with center (x,y) and the third parameter specifies the radius of circle.

4. Ellipse
Syntax :- void ellipse(int x, int y, int startangle, int endangle, int xradius, int yradius);
Ellipse function is used to draw an ellipse, (x,y) are coordinates of center ellipse, startangle is starting angle, end angle is ending angle, and fifth and sixth parameters specifies X and Y radius of ellipse. To draw complete ellipse startangle and end angle should be 0 and 360.

Comments (0)

Post Your Comments


Hong Kong Office

Find Us On

Website Development Company
Digital Marketing
website development company in Hong Kong
website designer in pune