Anda di halaman 1dari 3

Onecore Home About Advertise Archives Turbo C++ graphics Part 2 In first part of the turbo c++ graphics

programming series,I explained about the graphics modes & standard library functions,drivers. If you havent read the first part, please go do that now.The first part describes the details on what you need to start the graphics programming using turbo C++. In short, you need Turbo C++ version 3.0 to run the program explained in this post. Drawing functions: There are many functions available to draw the shapes on the screen; its not possible for me to cover each & every function used in graphics programming so here i have explained the most widely used & effective functions, the efficient use of them allows you to create smooth graphics. rectangle (left,top,right,bottom) : This function draws a rectangle with (left,top) as upper left of the rectangle & (right,bottom) as its lower right of the corner.All you have to do is to put the right co-ordinates. e.g. rectangle (10,30,500,400); ellipse (x,y,stangle,endangle,xrad,yrad) : This function draws an elliptical arc.Here (x,y) are the co-ordinates of center of the ellipse. (stangle,endangle) are the starting and ending angles.If stangle=0 and endangle=360 then this function draws complete ellipse. e.g.ellipse(100,150,0,360,100,50); arc (x,y,stangle,endangle,rad) : This function draws the circular arc of the given color.(x,y) are the center point of the arc & arc travels from stangle to endangle.(rad) defines the radius of the arc. e.g. arc(120,160,300,90,70); line (x1,y1,x2,y2) : Line function draws a line between two specified points (x,y) towards (x2,y2).This function comes handy if you want to draw box like shapes or just plotting the graphs etc. e.g. line(100,50,100,400); You can set the line style using setlinestyle functions.This function specifies the type of line,pattern & the thickness that is going to appear on the screen.You have options like solid,dotted,centered,dashed etc. e.g. setlinestyle(style,0,1); putpixel(x,y,color) : This function is used to put apixel at specified points (x,y).It comes handy when we have to plot a point of specified color at desired location.(color) can be defined in function as white or BLUE or specify the color code. e.g. putpixel(100,150,WHITE); bar (left,top,right,bottom): This function draws the filled-in,rectangular,two-dimmensional bar.It is filled using the fill pattern and fill color. Color palettes The graphics.h has declaration about 16 colors.In order to use the color in your program you have to use the functions like setcolor( ) ,setbkcolor( ) & setfillstyle( ).The function setcolor( ) sets the value of current drawing color to color.setfillstyle( ) sets the current fill pattern and fill color.setbkcolor( ) sets the value for background color,which is by default black. Below is the table that describes the value for each color that are declared in the graphics.h file. Color Value

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 Here is an example that makes use of all the available functions explained above, so write the code,compile and observe the effects. #include"graphics.h #include"conio.h" void main() { int gd=DETECT, gm; initgraph(&gd, &gm, "c:/tc/bgi "); circle(330,180,100); rectangle (10,30,500,400); ellipse(100,150,0,360,100,50); arc(120,160,300,90,70); line(100,50,100,400); getch(); closegraph(); restorecrtmode (); } By executing the functions in this program you will observe the circle, rectangle, ellipse, arc & line on the screen. I hope I have covered decent amount of information regarding the basics of the graphics programming using Turbo C++. I hope above information helped, again any suggestions are welcome.

-lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32

Anda mungkin juga menyukai