Graphics in C programming

 

If you want to create a colorful and attractive project in C language then you can choose graphics because graphics in c allows us to create different types of geometrical shapes like circle, rectangle, line, square, arc etc and we can also apply color on these shapes.

In this type of programming we can draw different kinds of geometrical shape for example circle, rectangle, square, line etc in different color.

Initialization of graph

void initgraph(int *Graphics_driver, int *Graphics_mode, char *Driver_directory_path);

1.initgraph is a predefined function which is used to initialize the graph. It has three parameters. It loads the passed graphics driver then changes the system into graphics mode.
2.Graphics_driver specifies the graphics driver. It is set to DETECT.
3.Graphics_mode specifies the graphics mode.
4.Driver_directory_path specifies the directory where all the graphics driver files are located.

Draw a Circle 

Syntax->circle(from-left,from-top,radius)

Here from-left is the distance in pixel from the left of screen similarly from-top is the distance in pixel from the top of the screen.

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode 
    circle(150,200,50);
    getch();
    closegraph();//closing of graphic mode 
    return 0;
}



Draw a Line

Syntax->line(min-x,min-y,max-x,max-y)

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode 
    line(150,150,250,250);
    getch();
    closegraph();//closing of graphic mode 
    return 0;
}


if you want to create a horizontal  line then min-y and max-y should be of same length.
for example line(150,100,250,100); you can try this you will get horizontal line as an output.

if you want to create a vertical line then min-x and max-x should be of same length.
for example line(100,250100,400); you can try this you will get vertical line as an output.

Draw a Rectangle

Syntax->rectangle(min-x,min-y,max-x,max-y)


#include<stdio.h>
#include<graphics.h>
#include<conio.h>
int main() {
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\tc\\bgi"); //initialization of graphic mode 
    rectangle(150,150,350,250);
    getch();
    closegraph();//closing of graphic mode 
    return 0;
}

Here I am requesting if you found this post was helpful for you then let me know by your comment in below comment box and share it with your friends. Also you can contact me on Instagram @rajusunagar_

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thank you!!.......

Post a Comment

0 Comments