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:
- int X1: This is the starting coordinate of the line. This is the horizontal coordinate of any line. This is always the integer in nature. This is the starting X coordinate of the lines.
- int Y1: This also falls under the starting coordinates. This is the vertical coordinate of any line. This is always the integer in nature. This is the starting Y coordinate of the lines.
- int X2: This is the ending coordinate of the line. This is the horizontal coordinate of any line. This is also an integer in nature. This is the ending X coordinate of the lines.
- int Y2: This also falls under the ending coordinates. This is the vertical coordinate of any line. This is also an integer in nature. This is the ending Y coordinate of the lines.
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.
- setcolor(color): This is the function that is needed to make a colorful line. Using this function along with the Line() function, users can able to draw a colorful line. There in this function, we have to provide the color name as the argument. This function needs to be placed before the line function. This will help to provide the appropriate output.
- setlinestyle(int linestyle, unsigned pattern, int thickness): This function basically used for two main reasons. One is by the help of this function, we can able to draw different lines. Like we can able to draw the dotted line also. This function also helps to make a thick like. The last argument is used for making a width line. The first two functions are needed when we have to make some other line pattern.
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:
- Step 1: Here, we will first include the necessary header file for working on the computer graphics.
- Step 2: Then we color the line using setcolor() function. This will help to color any diagram easily. Here, we have colored the line Green.
- Step 3: Now, we will use the line attributes. As this is the horizontal line, we have to keep same the values of Y coordinates. This means the Y1 & Y2 will be the same. The distance will depend upon the difference between X1 & X2.
- Step 4: We have to close the graph using closegraph() function.
Example 1: