Computer Graphics Programs

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:
For all the Graphics programs, Follow below-mentioned instructions before you run the program.
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();
}

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
Circle Graphic Programs
Program to Draw a Circle using Mid Point Algorithm
Program to Draw a Circle using Bresenham's Algorithm
Program to Draw Circle (Simple Program)
Program to draw a Circle having Changing its Color and Design
Program to draw a Circle using Direct Algorithm
Ellipse Graphic Programs
Program to draw an Ellipse using Mid - Point Ellipse Algorithm
Program to draw an Ellipse with Different Colours
Program to draw Polar Ellipse
Program to draw an Ellipse Showing Two Axis
Miscellaneous Graphic Programs
Program to Make a Fish
Program to move Fish
Program to make Flag
Program to make Hut
Program to make Kite
Program of Road Animation
Program of Scaling Transformation
Program to move person having balloons
C program to draw Man Walking In the Rain With An Umbrella
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

Post a Comment

11 Comments

  1. Could you please tell me how draw a book library ?

    ReplyDelete
  2. could you please tell me how to create diagram of smiley face with help of circles,arcs and lines

    ReplyDelete
    Replies
    1. Hi Amar,

      Follow 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

      Delete
    2. thanks it was so usefull

      Delete
  3. could you please tell me how to create diagram of human body using circle,lines,rectangle

    ReplyDelete
  4. Hi Amar,

    This 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...

    ReplyDelete
  5. can you give a program to draw a outline of india and a flag

    ReplyDelete
  6. can u give a program for
    rising sun

    ReplyDelete
    Replies
    1. Hi KAVYALAKSHMI R,

      Below 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

      Delete
  7. can you please upload a code for generalised bresenhams line drawing algorithm with a user created function

    ReplyDelete
  8. would you tell me how to draw curve in computer graphics plz reply fast

    ReplyDelete