Functions in Graphics

 • There are many built-in functions in Turbo c (BGI) Borland Graphics Interface is a graphics library that supports graphics in Turbo C.

• Note: This function is only supportable in Turbo c (BGI compliers is only available in turbo c.

• There are total 50 built-in functions available for use, we will discuss it one by one.

• Note: A short discription, Example and a program for each function.

• So let's start with Basic one:

1) initgraph(&gd, &gm," path of bgi")  

=> This function is used to initialize terminal default mode i.e. text mode into graphic mode.

=> Parameter: 

1) The address of gd.

2) address of gm.

3) path of BGI files.

* gd is graphic driver(instruction) which is initialised to DETECT which is a macro define in "graphic.h" header file.

* gm is graphic mode.

* Path where your BGI files are present (you have to adjust this accordingly where you Turbo C compiler is installed).

🎨Program Link:

👇 https://github.com/Rinky6767/Computer-Graphics/blob/af10a0110bfd2af98747962887df65c44b69e431/Built%20in%20functions/initgraph 

Output: It will be a black screen but in graphic mode.


2) closegraph

=> Is used to close graph mode and switch back in default (text) mode.


3) Bar function

=> Is used to draw a bar graph.

=> Syntax: bar( x_top,y_top,                       x_bottom,y_bottom)

• 


=> In above Image there is two points which denotes x_top & y_top one point and x_bottom & y_ bottom as second point.

• 


=> When those 2 points are join we get a bar and yeah it's done through bar function, you have to just give proper co-ordinates.

=> Example bar(100, 300, 250, 450)

 • so 100 is on x-axis top and 300 on y-axis top, 150 on x-axis bottom and 450 on y-axis bottom.

* Note: graph coordinate is little different here: 


=> Above image depict the coordinate system of graphic.

=> Output: bar(100, 300, 250, 450)


🎨Program we will plot a program for census of population of last 25 year's base on arbitrary values.

• This program consist of following built-in functions:

1) setbkcolor

2) setcolor,

3) bar,

4) outtextxy, and 

5)  settextstyle 

• So let's first understand this functions.

1) setbkcolor

• This function is used to change the current background color of screen (terminal).

• Remember default background color of terminal is black and default drawing color is white.

• Syntax: void setbkcolor(int color or name of color);

• Ex: setbkcolor(YELLLOW)


2) setcolor 

• setcolor() is used to change current "drawing" color.

• Remember that default drawing color is WHITE.

• Ex:  setcolor(RED) or setcolor(4) changes the current drawing color to RED. 

• Available color in Turbo C graphics are as follows:

Colors table

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

3) outtext and outtextxy 

**Do not use text mode functions like printf, gotoxy etc while working in graphics mode. 

Also note '\n' or other escape sequences do not work in graphics mode. You have to ensure that the text doesn't go beyond the screen while using outtext.

• outtext function displays text at current position, whereas outtextxy displays text at mentioned position before that knowing syntax of both function is very important.

• Syntax:

a) outtext(" Text")

b) outtextxy (int x-point, int y-point," Text")

• Ex: outtext("Computer Graphics")

• Ex: outtextxy (200,300,"Computer Graphics")

4) settextstyle 

• settextstyle function is used to change the current style of text.

• By using it we can modify the size of text, change direction of text and change the font of text.

•  syntax: void settextstyle( int font, int direction, int charsize)

• a) Direction :

1)  HORIZ_DIR (Left to right) 

2)  VERT_DIR (Bottom to top).

• b) Font: 

 Name.                             Value

DEFAULT_FONT             0

TRIPLEX_FONT              1

SMALL_FONT                 2

SANS_SERIF_FONT        3

GOTHIC_FONT                4 

SCRIPT_FONT                  5

 SIMPLEX_FONT              6

 TRIPLEX_SCR_FONT       7

 COMPLEX_FONT             8

 EUROPEAN_FONT           9

 BOLD_FONT                     10

• Ex: settextstyle(0, HORIZ_DIR, 1);

🎨Program Link(census):

👇https://github.com/Rinky6767/Computer-Graphics/blob/af10a0110bfd2af98747962887df65c44b69e431/Built%20in%20functions/setbkcolor_setcolor_bar_outtextxy_settextstyle

Output: 


• In next post we will see some other amazing functions like circle, rectangle and other shapes.


*You can leave a comment if you have doubt in it.










Comments

Popular posts from this blog

Functions of graphics

Line Basic Concepts

Shadow Mask technique