In the previous post I discussed few important functions mostly used to initialize and destroy the graphics mode in DOS environment.
Today I will discuss graphics functions to draw different shapes and lines.
So here we go by starting the line function which is most important function in creating any graphics.
This function draws a line in the graphics mode.
void line(int startx, int starty, int endx, int endy)
This function draws an arc from start to the end point. It uses the radius and the angle inputted in the function parametsr. Function prototye is
void arc (int x, int y, int start, int end, int radius)
The bar() functions draws a rectangular bar on the screen. It takes four parameters of type int which are infact the points on the graphics screen, and fills the bar with the defined fill-pattern. Function prototye is
void bar(int left, int top, int right, int bottom)
Here left & top are the starting point for the rectangular bar from x and y coordinates respectively and right & bottom are the ending point.
As the name suggests that this function will draw the 3 Dimensional rectangular bar on the screen. Bar3d function takes six parameters of which four are the points , fifth one is the depth of the bar and sixth is the flag to indicate the 3D view. Here is the prototype of the bar3d function.
void bar3d(int left, int top, int right, int bottom, int depth, int topflag)
Draws the circle on the screen using a point(x,y) and the radius for the circle.
void circle(int x, int y, int radius)
This function draws an outline of a polygon.
void drawpoly(int numpoints, int far *points)
Here numpoints is the number of end points in the polygon. And points is the integer array which contains the x and y coordinates of the points.
Draws an ellipse using the current drawing color.
void ellipse(int x, int y, int start, int end, int xradius, int yradius)
This function fills an object drawn on the graphics screen with the defined color and fill pattern. Now if the x,y coordinates lie within the boundries of the object then it will fill the interior of the object otherwise out side the object.
void floodfill(int x, int y, int border)
Displays a text string on the screen in graphics mode.
void outtext(char far *str)
Displays the text at a specified position in graphics mode.
void outtext(int x, int y, char *str)
Prints a pixel at the specified point on the screen.
void putpixel(int x, int y, int color)
Draws a rectangular box on the screen using the points given in the parameters.
void rectangle(int left, int top, int right, int bottom)
I hope this explanation of common functions present in graphics.h library would help you learn graphics programming in C language. If you guys need any help, you are most welcome to ask and I would try to help you guys out.
In the next few days I will write a sample program which will demonstrate the use of these functions as well as the way to initialize the graphics mode in c programming language.
Here’s Must-Read List of C programming books for beginners
With over 600 5-star reviews on Amazon, readers agree that C Programming Language, 2nd Edition by Brian Kernighan and Dennis Ritchie is the best C Programming book for Beginners. The authors present the complete guide to ANSI standard C language programming. Written by the developers of C, this new version helps readers keep up with the finalized ANSI standard for C while showing how to take advantage of C’s rich set of operators, economy of expression, improved control flow, and data structures.
Throw out your old ideas about C and get to know a programming language that’s substantially outgrown its origins. With this revised edition of 21st Century C, you’ll discover up-to-date techniques missing from other C tutorials, whether you’re new to the language or just getting reacquainted.
Greg Perry is the author of over 75 computer books and known for bringing programming topics down to the beginner’s level. His book C Programming Absolute Beginner’s Guide, is today’s best beginner’s guide to writing C programs–and to learning skills to use with practically any language. Its simple, practical instructions will help you start creating useful, reliable C code, from games to mobile apps. Plus, it’s fully updated for the new C11 standard and today’s free, open source tools!
KN King tackles on some C standard library specifics header by header in his C Programming: A Modern Approach book. The second edition maintains all the book’s popular features and brings it up to date with coverage of the C99 standard. The new edition also adds a significant number of exercises and longer programming projects, and includes extensive revisions and updates.
Simon Monk, a Ph.D. in software engineering, writes this great little book for learning to program the arduino using C language. This bestselling guide explains how to write well-crafted sketches using Arduino’s modified C language. You will learn how to configure hardware and software, develop your own sketches, work with built-in and custom Arduino libraries, and explore the Internet of Things—all with no prior programming experience required!