Graphics in C Language
Graphics in C Language
www.sirjameel.com
80 columns, 50 rows
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
Drawing a Circle
#include<conio.h> #include<graphics.h> main() { int gd=DETECT, gm; initgraph(&gd, &gm, C:/TC/bgi ); circle(320,240,100); getch(); closegraph(); }
www.sirjameel.com
circle(320,240,100);
Explanation
A Circle takes a total of 3 arguments. The first two arguments are used to define center of the circle in x and y co-ordinates. Since screen has a size of 640 pixels in x-axis, so 320 is the center of x-axis. And screen has the size of 480 pixels in y-axis, so 240 is the center of y-axis. Third argument of the circle is its radius in pixels. In our example the radius of www.sirjameel.com is 100 pixels. the circle
www.sirjameel.com
arc(midx, midy,starting-angle,ending-angle,radius);
www.sirjameel.com
arc(midx, midy,starting-angle,ending-angle,radius);
Explanation:
Arc is used to draw circular arc Arc takes 5 arguments, all of the int type. First two arguments define the center of the arc to place on the screen. Third and Fourth arguments are starting and ending angles of the arc. Fifth argument is the radius of the arc in pixels.
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
(200,200)
www.sirjameel.com
www.sirjameel.com
setfillstyle(STYLE,COLOR);
www.sirjameel.com
setfillstyle(STYLE,COLOR);
Explanation:
The setfillstyle(STYLE,COLOR); sets the fill pattern and color. Total of 13 styles are available to C-Compiler, which are as under:
EMPTY_FILL, SOLID_FILL, LINE_FILL, LTSLASH_FILL, SLASH_FILL, BKSLASH_FILL, LTBKSLASH_FILL, HATCH_FILL, XHATCH_FILL, INTERLEAVE_FILL, WIDE_DOT_FILL, CLOSE_DOT_FILL, USER_FILL.
We can specify the color of the object either by writing directly color name all in CAPITAL LETTERS like RED, GREEN, or by writing a corresponding equillent number of the color, like 0 for BLACK, 1 for BLUE and so on. Similarly the fill pattern can also be replaced by their corresponding numbers, ie 0 for EMPTY_FILL, 1 for SOLID_FILL , and so on.
Hence setfillstyle(SOLID_FILL, BLUE); is equall to setfillstyle(1, 1); Both will yield the same result.
www.sirjameel.com
setfillstyle(STYLE,COLOR);
Example1: setfillstyle(EMPTY_FILL,BLUE); bar(20,20,100,200);
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
Explanation:
Ellipse is used to draw an elliptical arc. Ellipse takes 6 arguments, all of the int type. First two arguments define the center of the ellipse to place on the screen.(ie x and y co-ordinates) Third and Fourth arguments are starting and ending angles of the ellipse. Fifth argument is the radius of the ellipse in x-axis, and sixth argument is the radius of the ellipse in y-axis.
www.sirjameel.com
Example1: ellipse(320,240,0,360,50,100);
www.sirjameel.com
Example2: ellipse(320,240,0,360,100,100);
www.sirjameel.com
Example3: ellipse(320,240,0,360,100,50);
www.sirjameel.com
Example4: ellipse(320,240,0,180,100,50);
www.sirjameel.com
Example5: ellipse(320,240,180,0,100,50);
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
www.sirjameel.com
Value 0 1
www.sirjameel.com
www.sirjameel.com