Circle, arc, pieslice are declared as follows:
Declaration:
* void far arc(int x, int y, int stangle, int endangle, int radius);
* void far circle(int x, int y, int radius);
* void far pieslice(int x, int y, int stangle, int endangle, int radius);
Remarks:
* arc draws a circular arc in the current drawing color.
* circle draws a circle in the current drawing color.
* pieslice draws a pie slice in the current drawing color, then fills it using
the current fill pattern and fill color.
Arguments:
* (x,y): Center point of arc, circlew, or pie slice
* stangle: Start angle in degrees
* endangle: End angle in degrees
* radius: Radius of arc, circle, and pieslice
Here, stangle and endangle are in degrees starting from the +ve x-axis in the polar coordinate system in the anti-clockwise direction. if stangle is 0, endangle is 360, it will draw a full circle. Refer this figure for clear idea: For the details of current color, fill color and fill patterns, refer the sections Lines and Colors.

Angle calculations
Another basic shape that we come across is a rectangle. To draw a border, use rectangle with the coordinates of outline, to draw a square use rectangle with same height and width. drawpoly() and fillpoly() are two functions useful to draw any polygons. To use these functions, store coordinates of the shape in an array and pass the address of array as an argument to the function. By looking at the output of the previous program, you can understand what drawpoly is. fillpoly is similar except that it fills in the shape with current fill color.
Declaration:
* void far rectangle(int left, int top, int right, int bottom);
* void far drawpoly(int numpoints, int far *polypoints);
* void far fillpoly(int numpoints, int far *polypoints);
Remarks:
* Rectangle draws a rectangle in the current line style, thickness, and drawing color.
* Drawpoly draws a polygon using the current line style and color.
* Fillpoly draws the outline of a polygon using the current line style and color, then fills the polygon using the current fill pattern and fill color.
Arguments:
* (left,top) is the upper left corner of the rectangle, and (right,bottom) is its lower right corner.
* numpoints: Specifies number of points
* Polypoints: Points to a sequence of (numpoints x 2) integers. Each pair of integers gives the x and y coordinates of a point on the polygon.
To draw a closed polygon with N points, numpoints should be N+1 and the array polypoints[] should contain 2(N+1) integers with first 2 integers equal to last 2 integers.
Let us study more about shapes latter. Here is some idea about colors. There are 16 colors declared in graphics.h as listed bellow.
BLACK : 0
BLUE : 1
GREEN : 2
CYAN : 3
RED : 4
MAGENTA : 5
BROWN : 6
LIGHTGRAY : 7
DARKGRAY : 8
LIGHTBLUE : 9
LIGHTGREEN : 10
LIGHTCYAN : 11
LIGHTRED : 12
LIGHTMAGENTA : 13
YELLOW : 14
WHITE : 15
To use these colors, use functions setcolor(), setbkcolor() and setfillstyle(). setcolor() function sets the current drawing color. If we use setcolor(RED); and draw any shape, line or text after that, the drawing will be in red color. You can either use color as defined above or number like setcolor(4);. setbkcolor() sets background color for drawing. Setfillstyle sets fill pattern and fill colors. After calling setfillstyle, if we use functions like floodfill, fillpoly, bar etc, shpes will be filled with fill color and pattern set using setfillstyle. These
function declarations are as follows.
Declaration:
* void far setfillstyle(int pattern, int color);
* void far setcolor(int color);
* void far setbkcolor(int color);
Remarks:
* setfillstyle sets the current fill pattern and fill color.
* setcolor sets the current drawing color to color, which can range from 0 to getmaxcolor.
* setbkcolor sets the background to the color specified by color.
The parameter pattern in setfillstyle is as follows:

Parameter pattern in setfillstyle
Here is an example program with colors, pixels, bar, cleardevice etc. stdlib.h is used for random number generation. We have a function random(no), it returns a random number between 0 an no. The effect is by drawing random radius, random color circles with same center and random pixels. kbhit() function(defined in conio.h) returns a nonzero value when a key is pressed in the keyboard. So, the loop will continue until a key is pressed.
/*
random.c
some graphics effects using random numbers.
example 1.2
by HarshaPerla, http://eharsha.tk
*/
#include “graphics.h”
#include “conio.h”
#include “stdlib.h”
void main()
{
int gd,gm;
gd=DETECT;
initgraph(&gd, &gm, “”);
setcolor(3);
setfillstyle(SOLID_FILL,RED);
bar(50, 50, 590, 430);
setfillstyle(1, 14);
bar(100, 100, 540, 380);
while(!kbhit())
{
putpixel(random(439)+101, random(279)+101,random(16));
setcolor(random(16));
circle(320,240,random(100));
}
getch();
closegraph();
}
Pages: 1 2
Description :
This is the one stop educational site for all Electronic and Computer students. If you want to learn something new then we are here to help. We work on Microcontroller projects, Basic Electronics, Digital electronics, Computer projects and also in basic c/c++ programs.
#Home #Sitemap #Submit #Terms of Use
Copyright©2011 electrofriends.com All Rights Reserved
Contact:info@electrofriends.com | Powered by Dhyeya
hi… this gaurav kabra
those wo havong error for not defined _closegraph
thi file graphics.h must be included in your program
you should use the statement as #include”graphics.h”
also for the error after execution like use ‘initgraph’
the path of bgi folder is required in the initgraph()
the folder can be found in tc folder in c: & use’/’ in the path insted ‘\’
i have tried all the things which are specified above for graphics programming
m a beginner but after all correction i have one error constantly coming on the execution screen
after pressing alt f5 it shows
BGI error:couldnt initialize graphics (use initgraph)
plz help me………..:’(
this is the code i have written
#include
#include
void main()
{
int gd=DETECT, gm;
initgraph(&gd, &gm,”E:\TC\BGI” );
circle(200,100,150);
getch();
closegraph();
}
help plz………….
Hi,
I want to draw a graph for the binary value of lenght 1byte in turbo C.
Kindly help me with the code as I am new to turbo C graphics.
@shabeeb ahamed,
its a linker error buddy. go to option and then linker, and then put [X] to graphics mode…
Hello , Can anyone tell me how to toggle between Graphics mode and textual mode in c please reply fast.
ppl help me out na..
i need to use bck grnd color n font color so juz tell me hw to use under
ssry how to use under
pls help me out..
i need to copy graphics output to word file.. how to take the screen shot..
prtscr_Sysrq is not working.. pls help me out guys..
Hi Jins, The print screen key is not working in case you want to take the screenshot. you need to use Dos box, which will be useful for this. Using this you can mount any directory (folder) and run the program in dos box window, then the printscreen key will work.
I’m using Win7, & I’m unable to run graphic programs under small screen & Win7 doesnt support fullscreen for Turbo C.
Can U solve my problem… plzzz….!
when i run the following program, i got an error
program
#include
#include
#include
void main()
{
int gd=DETECT, gm;
initgraph(&gd, &gm, “c:\\turboc3\\bgi ” );
circle(200,100,150);
getch();
closegraph();
}
error
BGI error:graphics not initialized(use”initgraph”)
graphics program doesnot run in my tc …but it compile the progm succsfully..but….
can help me…
please help me to run this program#
include
#include
void main()
{
int gd=DETECT, gm;
initgraph(&gd, &gm, “c:\\turboc3\\bgi ” );
circle(200,100,150);
getch();
closegraph();
}
i love you tatay ko nanay ko tiyo ko mahal kita nakin..
please help me to run the world..
i mean hep me to make a program using graphics….text me 09077272996
Power Graphics Using Turbo C++
if any has code for Power Graphics Using Turbo C++ please email to data24by7 at geemail com
if any has code for Power Graphics Using Turbo C++ please email to data24by7@gmail.com