Monday, March 5, 2012

Drawing shapes

C Graphics library provides many APIs to draw different shapes. Like Lines,Rectangles, Cirle, Arc, Filled rectangle and 3D rectangle. The following example illustrates drawing shapes in C Graphics using  line(), circle(), arc(), rectangle(), bar(). Use setcolor() to change the color of drawing line. There are other ways to change the line style and fill style which will be covered in later posts.







/* Presented by www.ncooltips.com
 * Drawing shapes example.
*/
#include<stdio.h>
#include<conio.h>
#include<graphics.h>


void main()
{
int gdriver=DETECT,gmode=0;
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

//Line
line(10,200,200,200);

// Reactangle
rectangle(10,10,100,100);

//Filled rectangle
bar(130,10,230,100);

//3d Bar
bar3d(250,30,350,100,20,1);

//Circle
circle(250,250,50);

//Arc
arc(250,250,0,90,60);

getch();

cleardevice();
closegraph();

}



Pin It
Related Posts Plugin for WordPress, Blogger...