Computer Graphics Programs in C - What you will learn?
You are the one who is interested in learning the fundamentals of the graphical programming languages. This page contains a list of fundamental graphics programs for various shapes. You will learn basics to draw geometrical shapes like circle, ellipse, rectangle, etc.
We will also learn graphics programming in c to draw sample program of curves, objects with various colors, 3d graphics programming, simple animation programs, and algorithms programs.
How to start writing Computer Graphics Code in C
When you start writing computer graphics code. The first step is to initialize the graphics drivers using the initgraph() function given in graphics.h header file.
Must include graphics.h header at the beginning of a program to run any kind of graphics program.
For loading graphics drivers, we need to call initgraph() method.
initgraph() is also part of graphics.h library. Function initgraph() accepts 3 parameters. Which are graphdriver, graphmode and pathtodriver.
void initgraph(int far *graphdriver, int far *graphmode, char far *pathtodriver);
Graphdriver accepts integer value, which specifies the graphics drivers to be used. Graphmode sets the available resolution for the detected graphic drivers, which accepts integer value. Pathdriver specifies the directory path for graphics drivers.
Instruction:
1. Find initgraph(&gd, &gm, ""); in Program.
2. Write the path of BGI Folder, which there inside TC.
Like, initgraph(&gd, &gm, "C://TC//BGI");
or initgraph(&gd, &gm, "C://TurboC++//Disk//TurboC3//BGI");
3. Copy "EGAVGA.BGI" BGI File from BGI Folder and Paste it to BIN Folder.
Sample graphics program to draw a line in c
// graphics driver files
#include <graphics.h>
int main()
{
// initialize the graphics mode
int gd = DETECT, gm; initgraph(&gd, &gm, "");
// line for x1, y1, x2, y2
line(150, 150, 450, 150);
// line for x1, y1, x2, y2
line(150, 200, 450, 200);
// line for x1, y1, x2, y2
line(150, 250, 450, 250);
getch();
// closegraph function closes the graphics
// mode and deallocates all memory allocated
// by graphics system .
closegraph();
}
#include <graphics.h>
int main()
{
// initialize the graphics mode
int gd = DETECT, gm; initgraph(&gd, &gm, "");
// line for x1, y1, x2, y2
line(150, 150, 450, 150);
// line for x1, y1, x2, y2
line(150, 200, 450, 200);
// line for x1, y1, x2, y2
line(150, 250, 450, 250);
getch();
// closegraph function closes the graphics
// mode and deallocates all memory allocated
// by graphics system .
closegraph();
}
Computer Graphics Functions |
---|
Arc Function |
Bar Function |
Circle Function |
Cleardevice Function |
Closegraph Function |
Outtext Function |
kbhit Function |
Line Graphic Programs |
---|
Program to Draw a Line using DDA Algorithm |
Program to Draw a Line using Bresenhams Algorithm |
Program to draw a line using Cartesian Slope-Intercept Equation |
Other Graphics Programs |
---|
Program to display Screen Sever |
Smily Face Animation Graphics Program |
OpenGL Programs |
---|
OpenGL program to draw a line |
OpenGL program to draw a line using dda algorithm |
OpenGL program to draw Sun Rise and Fall |
11 Comments
Could you please tell me how draw a book library ?
ReplyDeletecould you please tell me how to create diagram of smiley face with help of circles,arcs and lines
ReplyDeleteHi Amar,
DeleteFollow the below link to draw smily face using circle(), ellipse(), fillellipse(),etc many...
http://www.askforprogram.in/2016/06/draw-smily-face-animation-icon-C-Computer-Graphics-Program.html
Revert if you have any difficulty in understanding it.
Thanks
thanks it was so usefull
Deletecould you please tell me how to create diagram of human body using circle,lines,rectangle
ReplyDeleteHi Amar,
ReplyDeleteThis are simple functions. You just need to use your imagination and arrange functions (circle,line,ractangle,etc) to draw human body.
Though i can help you draw face, else you have to do on your own, that way you will lear remaining...
Let me know your call...
can you give a program to draw a outline of india and a flag
ReplyDeletecan u give a program for
ReplyDeleterising sun
Hi KAVYALAKSHMI R,
DeleteBelow is the requested program, i would suggest you to read all the function used in and try to understand it.
"Program to draw Sun rise and fall in OpenGL : Computer Graphics"
http://www.askforprogram.in/2016/10/program-to-draw-sun-rise-and-fall-in-opengl-computer-graphics.html
Thanks & Regards
can you please upload a code for generalised bresenhams line drawing algorithm with a user created function
ReplyDeletewould you tell me how to draw curve in computer graphics plz reply fast
ReplyDelete