Graphics in GNU – GCC

How to run graphics.h in gcc? For this you’ve to install libgraph. Refer the following post:

Libgraph

After installing libgraph, we just need to initialize it in graphics.h using following code in main file:

int gd,gm=VGAMAX;

gd=DETECT;

initgraph(&gd,&gm,NULL);

Type: $ sudo vim shape.cpp

#include”graphics.h”
//#include”myconio.h”
#include”iostream”

using namespace std;

int main()

{

int gd=DETECT;

int gm=VGAMAX;

initgraph(&gd,&gm,NULL);

int i,x=10;

char str[3]=”0″;

setbkcolor(WHITE);

setcolor(12);

circle(50,50,40);

circle(110,50,40);

line(22,80,80,140);

line(80,140,138,80);

floodfill(50,50,12);

floodfill(110,50,12);

floodfill(80,50,12);

floodfill(80,100,12);

getch();

closegraph();

return 0;

}

To Compile use: g++ shape.cpp -o shape.o -lgraph

To Run: ./shape.o

Screenshot from 2014-08-20 13:32:47

^_^

Advertisements

3 thoughts on “Graphics in GNU – GCC

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s