C Graphics Source Code

Line drawing using line function

Draws a line using the inbuilt line function. Takes the end co-ordinates of the line from the user.Draws a line using the inbuilt line function


Displaying text in graphics mode

Displays a string of text in graphics mode at a specified location.Takes the string as well as the position of display from the user.


Draws a circle using circle function

Draws a cirlce using the inbuilt circle function available in the BGI library.Takes the radius and the centre co-ordinated from the user.


Draws a circle using circle function along with label

Draws a cirlce using the inbuilt circle function available in the BGI library.Takes the radius and the centre co-ordinated from the user. Also displays the label using outtextxy() function


Thick line using built in function

Draws a thick line using inbuilt line() function. Takes the line co-ordinates from the user to plot the desired line



DDA Line

Draws a line using DDA Algorithm. Takes the line co-ordinates from the user to plot the desired line.The program starts with one given end point and then calculates each successive pixel that lies on the line using DDA Algorithm


DDA Dotted Line

Draws a dotted line using DDA Algorithm. Takes the line co-ordinates from the user to plot the desired line.The program starts with one given end point and then calculates each successive pixel that lies on the line using DDA Algorithm.Alternate pixels are plotted to produce the dotted line effect.


Dashed line using DDA Algorithm

Draws a dashed line using DDA Algorithm. Takes the line co-ordinates from the user to plot the desired line. The program starts with one given end point and then calculates each successive pixel that lies on the line using DDA Algorithm.To make the line dashed ,the program plots some pixels in order and then skips some pixels to produce the dotted effect.


Dashed and dotted line using DDA Algorithm

Draws a dashed and dotted line using DDA Algorithm. Takes the line co-ordinates from the user to plot the desired line.The program starts with one given end point and then calculates each successive pixel that lies on the line using DDA Algorithm.To make the line dashed and dotted,the program plots some pixels in order and then skips some pixels to produce the dotted effect.Alternate pixels are plotted to produce the dotted line effect.Applying these two simultaneously we the dashed-dotted line effect.


Circle drawing using DDA Algorithm

Draws a circle using DDA Algorithm. Takes the circle parameters (centre and radius)from the user to plot the desired circle.The program calculates each successive pixel that lies on the circle using DDA Algorithm.


Circle drawing using Bresenham Algorithm

Draws a circle using Bresenham Algorithm. Takes the circle parameters (centre and radius)from the user to plot the desired circle.The program calculates each successive pixel that lies on the circle using Bresenham Algorithm.


Scaling tranformation in C graphics

Scaling transformation in C graphics.
The program demonstrates how to perform scaling transformation of a given polygon object (using C/C++ graphics) to increase or decrease the size of the given object along with source code.

Scaling is done by multiplying the given object matrix with the scaling tranformation matrix,to obtain the new image of the required size.
The program prompts the user for number of vertices in the polygon and takes their vertex co-ordinates in a cyclic order. It then asks the user to for x-scale factor and y-scale factor.
The user is expected to enter the number of times to scale the given object in the respective direction.
The final image of the scaled object along with original object is drawn.


Shearing tranformation in C graphics

Shearing transformation in C graphics.
The program demonstrates how to perform shearing transformation of a given polygon object (using C/C++ graphics) along with source code.

Shearing is done by multiplying the given object matrix with the shearing tranformation matrix,to obtain the sheared image object.
The program prompts the user for number of vertices in the polygon and takes their vertex co-ordinates in a cyclic order. It then gives choice to the user to select x-shear or y-shear.
The user is expected to enter the number of times to shear the given object in the respective direction.
The final image of the sheared object along with original object is drawn.


Rotation tranformation in C graphics

Rotation transformation in C graphics.
The program demonstrates how to perform rotation transformation of a given object (using C/C++ graphics) with respect to a specific point along with source code.

The object co-ordinates are taken from the user and rotation transformation matrix is used to obtain the new image co-ordinates of the transformed object.
The program prompts the user for number of vertices in the polygon and takes their vertex co-ordinates in a cyclic order.It then asks the user for amount of rotation(angle in degrees) with respect to a specific point given by the user.
The user is expected to enter the appropriate angle of rotation(+ve anticlockwise,-ve clockwise). The final image of the rotated object along with original object is drawn.


Linear tranformation in C graphics

Linear transformation in C graphics.
The program demonstrates how to perform linear transformation of a given polygon object (using C/C++ graphics) to position the given object in the co-ordinate plane.

Translation is done by multiplying the given object matrix with the linear tranformation matrix,to obtain the new image at the required position.
The program prompts the user for number of vertices in the polygon and takes their vertex co-ordinates in a cyclic order. It then asks the user to for x-translation factor and y-translation factor. The user is expected to enter the appropriate positions to position/move the given object at a specific location.
The final image of the translated object along with original object is drawn.


Basic mouse programming in C - Show/hide mouse pointer in C

Basic mouse programming in C.

Show/hide mouse pointer in C.
This program demonstrates the initialization of mouse pointer in C and simply shows and hides the mouse pointer based on user input.
The program first checks for mouse support using the init() function.

It then waits for user input in a continuous loop:
on pressing s - mouse pointer is shown
on pressing h - mouse pointer is hidden
on pressing any other key - the program terminates


This program demonstrates how mouse can be enabled in C programs.