Open In App

Line Attributes in Computer Graphics

Computer Graphics is an important topic in the Computer Science domain. It is a type of coding practice that will print the necessary output images. One should have a good imagination to master Computer Graphics. Computer Graphics mainly can be written in C programming language or C++ programming language. Using any one of the programming languages, users can develop eye-catching output images, It generally uses the computer graphics card to produce the images. There are color options also. Using calculation & proper use of programming knowledge, users can develop any structure. From a simple car to Eiffel Tower, everything can be derived using computer graphics. There are many inbuilt functions in the Computer Graphics. The line is one of them.

Line Attributes In Computer Graphics:

The line is one of the major inbuilt functions in computer graphics, This helps to make more interactive & interesting images. There are many inbuilt functions are present. Like there are Circle, Arch, Eclipse, etc. All of this help to make a structure. Proper use of those functions helps to draw out particular images.



As the line is the function there some attributes or arguments are present. These help to draw a line in a better position. There are mainly four coordinates. Two are the starting coordinates & the two are for ending coordinates.

Syntax: 



line(int X1, int Y1, int X2, int Y2);

Associated Functions With Line Attribute:

The Line function can only be able to draw lines. Whenever there is a need to draw a line in computer graphics, we need to take the help of the Line function. But there is also some need to customize the line. Suppose, if the user wants to draw a Red car, then the lines will definitely be in Red color. Or a line needs to be thick in someplace. So, for that purpose, we need to make a width line there. All these things can’t able to do by a simple line function. For that purpose, we need to have some more functions.

Types Of Lines In Computer Graphics:

It is time to know about the types of lines that can be derived using the line attribute in computer graphics. Users can derive mainly three types of lines by playing with the attribute values of the lines.

Horizontal Lines:

Example 1:




// Horizontal Line code
#include <stdio.h>
 
// Required Header File
#include <conio.h>
#include <graphics.h>
int main()
{
 
    // Configuring The Graphics File
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\turboc3\\bgi");
 
    // Coloring The Line
    setcolor(GREEN);
 
    // Horizontal Line
    line(100, 300, 400, 300);
    getch();
 
    // Closing The Graphics
    closegraph();
    return 0;
}

Output:

 

Vertical Lines:

Example 2: 




// Vertical Lines code in Computer Graphics
#include <stdio.h>
 
// Required Header File
#include <conio.h>
#include <graphics.h>
int main()
{
    // Configuring The Graphics File
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\turboc3\\bgi");
    // Coloring The Line
    setcolor(BLUE);
    // Vertical Line
    line(600, 200, 600, 400);
    getch();
    // Closing The Graphics
    closegraph();
    return 0;
}

Output:

 

Tangent Lines:

Example 3: 




// Tangent Lines code for Computer Graphics
#include <stdio.h>
 
// Required Header File
#include <conio.h>
#include <graphics.h>
int main()
{
 
    // Configuring The Graphics File
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\turboc3\\bgi");
 
    // Coloring The Line
    setcolor(RED);
 
    // Tangent Line
    line(250, 400, 450, 500);
    getch();
 
    // Closing The Graphics
    closegraph();
    return 0;
}

Output:

 

Width Of Line In Computer Graphics:

Example 4:




// Width of Line code in computer graphics
#include <stdio.h>
// Required Header File
#include <conio.h>
#include <graphics.h>
int main()
{
 
    // Configuring The Graphics File
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\turboc3\\bgi");
 
    // Normal Width Line
    setlinestyle(0, 0, 1);
    line(300, 400, 700, 400);
 
    // Width Line
    setlinestyle(0, 0, 10);
    line(300, 700, 700, 700);
    getch();
 
    // Closing The Graphics
    closegraph();
    return 0;
}

Output:

 

Color Of Line In Computer Graphics:

Example 5:




// Color Of Line In Computer Graphics
#include <stdio.h>
 
// Required Header File
#include <conio.h>
#include <graphics.h>
 
int main()
{
 
    // Configuring The Graphics File
    int gd = DETECT, gm;
    initgraph(&gd, &gm, "C:\\turboc3\\bgi");
 
    // Coloring The Line With Green
    setcolor(GREEN);
    line(300, 400, 700, 400);
 
    // Coloring The Line With Yellow
    setcolor(YELLOW);
    line(300, 700, 700, 700);
    getch();
 
    // Closing The Graphics
    closegraph();
    return 0;
}

Output:

 


Article Tags :