Hello friends
Today I will show you how you can create simple graphics in Turbo C++ like basic shapes .
I have also uploaded the “Program Code” so that all of you can copy it on your system
So
in order to do so first we have to install a small free piece of
program called Dos Box which could be downloaded from the following
website
After downloading it we do the the following steps
Step
1 > Downloaded the software install it in your computer . I would
assume that you have installed the software in “C DRIVE”
Step 2 > Create a folder in your C drive “let name it as turbo”
Step
3> Now install Turbo C++ software inside the “turbo” folder or if
you have already installed it in your C drive then you should have a
folder called “TC” .In that case just copy the TC folder and paste it
inside “turbo” folder
Step 5>Now copy the EGAVGA.BGI file inside the BGI folder inside TC and paste it inside BIN folder
Location of EGAVGA.BGI will be “C:\turbo\TC\BGI”
the screen with the blue box will be our working screen
Step 7> now type the following in the window
mount c c:\turbo
and press enter , after that we will get this message
Step 8> now type
c:
and press enter
Step 9>Now we can type Dos commands and navigate to the TC.EXE file inside TC folder like this
cd TC press enter
cd BIN press enter
TC.EXE And press enter to start Turbo C++ IDE , so all of it look like this
if you get the blue IDE screen then it all ready to start programming
now we can use the following code to start programming
/////////////////////////////////////////////////////////////////////////////////////////////
//Hello India Program
////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
void main()
{
clrscr();
printf(" HELLO INDIA ");
getch();
}
///////////////////////////////////////////////////////////////////////////////////////////
//Drawing a line on screen
//////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
line(0,0,250,250);getch();
}
output of the program will be like this
////////////////////////////////////////////////////////////////////////////////////////////
//Drawing a circle
///////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");circle(250,250,50);
getch();
}
output of the program will be like this
/////////////////////////////////////////////////////////////////////////////////////////
//Drawing a square or rectangle
////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
rectangle(250,250,450,400);getch();
}
output of the program will be like this
//////////////////////////////////////////////////////////////////////////////////////////
//Drawing a eclippse
//////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
ellipse(250,250,0,360,100,60);
getch();
}
out put of the program will be like this
Ok
these were some basic shapes now let us draw some objects , please
forgave me I am not good at graphics my main aim is to give you some
idea to get going . If you want more accurate presentation feel free to
modify the code to get your best result
/////////////////////////////////////////////////////////////////////////////////////////
//Diagram of a car
////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
rectangle(100,200,200,250);
rectangle(220,200,320,250);
rectangle(90,190,330,290);
circle(150,290,30);
circle(270,290,30);
}
the output will be like this
//////////////////////////////////////////////////////////////////////////////////////////
//Diagram of a fish
/////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
ellipse(150,200,0,360,100,50);
circle(200,195,20);
ellipse(50,200,0,360,50,30);getch();
}
the output will be like this
/////////////////////////////////////////////////////////////////////////////////////////////
//Diagram of a kite
////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
line(220,140,300,140);
line(270,100,270,180);
line(220,140,270,100);
line(220,140,270,180);
line(270,100,300,140);
line(270,180,300,140);
getch();
} the output will be like this
So
these were some diagrams I made now let us use the same diagrams and do
some simple animation on them like moving them on screen
/////////////////////////////////////////////////////////////////////////////////////////////
//Car Moving
////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
do{
for(i=0;i<=500;i++)
{
delay(8);
cleardevice();
rectangle(100+i,200,200+i,250);
rectangle(220+i,200,320+i,250);
rectangle(90+i,190,330+i,290);
circle(150+i,290,30);
circle(270+i,290,30);
}
}while(!kbhit());
getch();
}
/////////////////////////////////////////////////////////////////////////////////////////////
//Fish Moving
////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
do{
for(i=0;i<=500;i++)
{
delay(8);
cleardevice();
ellipse(150+i,200,0,360,100,50);
circle(200+i,195,20);
ellipse(50+i,200,0,360,50,30);
}
}while(!kbhit());
getch();
}
////////////////////////////////////////////////////////////////////////////////////////////
//Kite Moving
////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm,i;
initgraph(&gd,&gm,"");
do{
for(i=0;i<=300;i++)
{
delay(8);
cleardevice();
line(220+i,140,300+i,140);
line(270+i,100,270+i,180);
line(220+i,140,270+i,100);
line(220+i,140,270+i,180);
line(270+i,100,300+i,140);
line(270+i,180,300+i,140);
}
}while(!kbhit());
getch();
}
Ok so we have come to our end but before that lets do a final program to draw the Indian flag and also color it
/////////////////////////////////////////////////////////////////////////////////////////////////Indian Flag
////////////////////////////////////////////////////////////////////////////////////////////////
#include<stdio.h>
#include<graphics.h>
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"");
setfillstyle(LINE_FILL,BLUE);
bar(0,0,800,800);
printf("JAY HIND");
setfillstyle(SOLID_FILL,BROWN);
bar(100,100,300,150);
setfillstyle(SOLID_FILL,WHITE);
bar(100,150,300,200);
setcolor(BLUE);
circle(200,175,25);
line(200,175,200,200);
line(200,175,200,150);
line(200,175,225,175);
line(200,174,174,174);
setfillstyle(SOLID_FILL,GREEN);
bar(100,200,300,250);
setfillstyle(SOLID_FILL,RED);
bar(98,98,100,700);
getch();
}
the output will be like this
tanx sir..
ReplyDeleteThis was realy helpfull..
If there is more of these please lt me knw.., am jst a beiginner..
Febinkt@gmail.com
nc
ReplyDeleteHow can we show hoisting of this indian flag
ReplyDeletehey usefull information
ReplyDeletebut i cant find my intigraph path..
can u help
my complier is differnet then urs
In my turbo c++ for windows 8 i get an error ...graphics not initialised even when i gave the path
ReplyDelete
ReplyDeleteThanks for sharing such a great blog..Keep posting..Very informative post
Nice but what about android and mac? i think this might helped your users https://www.jrpsc.org/turbo-c/
ReplyDelete