Onecore

  • Home
  • About
  • Advertise
  • Archives
  • Privacy Policy
  • Contact

Turbo C++ Graphics Part 2

software templates

In first part of the turbo c++ graphics programming series, I explained about the graphics modes & standard library functions,drivers. If you haven’t 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.

Check the installation video for Turbo C++ 3.0 on Modern Windows OS (64-bit)

Drawing functions:
There are many functions available to draw the shapes on the screen; it’s 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

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.

Comments

  1. kin says

    March 29, 2007 at 7:07 AM

    thanxs 4 ts information…it helped me alot

  2. vinay says

    May 29, 2007 at 1:52 PM

    thanx man….

  3. Edna Encia says

    July 6, 2007 at 9:53 AM

    Thanx for sharing every knowledge its give to student wide understanding in thier cited topics……thanx….

  4. K.R.Nekhelesh says

    July 7, 2007 at 7:07 AM

    This information was very useful. but can you proceed with more functions….?

  5. Faizal says

    July 25, 2007 at 5:31 PM

    Thanks for tutorial

  6. hari krishna says

    September 9, 2007 at 11:53 AM

    thanx for the info……
    i could use graphics in c because of you only..

  7. prateek says

    November 24, 2007 at 5:28 PM

    good website

  8. Afaash says

    January 8, 2008 at 5:01 PM

    Thanks a lot. It has helped me greatly

  9. nitu says

    January 12, 2008 at 11:10 AM

    this was of gr8 help .thax a lot

  10. gelbert05 says

    January 13, 2008 at 5:36 PM

    tnx people, the info here help me…

  11. Mumtaz Ahmad says

    January 28, 2008 at 5:46 AM

    this is highly informative site to learn graphic in c++ i got a lot of information by this and i will also suggest to my friends to visit this site.

software templates

Featured Articles

  • Sample Test Cases for Calendar App
  • Sample Test Cases for Dialog Box
  • Test Cases for Amazon Login Screen Page
  • Sample Test Cases for Online Editor
  • Sample Test Cases for Online Book Shopping

WPForms

ENDORSEMENT DISCLOSURE: In order for us to support our website activities, we may receive monetary compensation or other types of remuneration for our endorsement, recommendation, testimonial and/or link to any products or services from this website.

Copyright © 2019 . This website uses cookies to ensure you get the best experience on our website.