line() Function in C Graphics – Syntax and Example
Introduction to line() Function
The line() function is used to draw a straight line between two points on the graphics screen. The two points (x1, y1) and (x2, y2) represent the starting and ending coordinates of the line. The line() function is available in the traditional BGI (Borland Graphics Interface) graphics library through the graphics.h header file.
line() फंक्शन का उपयोग ग्राफिक्स स्क्रीन पर दो बिंदुओं के बीच एक सीधी रेखा खींचने के लिए किया जाता है। (x1, y1) और (x2, y2) रेखा के शुरुआती और अंतिम बिंदुओं के निर्देशांक (Coordinates) होते हैं। line() फंक्शन पारंपरिक BGI (Borland Graphics Interface) ग्राफिक्स लाइब्रेरी में उपलब्ध होता है, जिसके लिए graphics.h हेडर फाइल का उपयोग किया जाता है।
Syntax of line() Function
void line(int x1, int y1, int x2, int y2);Parameters:
x1: X-coordinate of the starting point.y1: Y-coordinate of the starting point.x2: X-coordinate of the ending point.y2: Y-coordinate of the ending point.
पैरामीटर्स:
x1: रेखा के शुरुआती बिंदु का X-coordinate।y1: रेखा के शुरुआती बिंदु का Y-coordinate।x2: रेखा के अंतिम बिंदु का X-coordinate।y2: रेखा के अंतिम बिंदु का Y-coordinate।
Example: C Program to Draw a Line Using line() Function
The following program demonstrates how to draw a straight line from point (100, 100) to point (200, 200) using the line() function.
निम्न प्रोग्राम line() फंक्शन की सहायता से (100, 100) बिंदु से (200, 200) बिंदु तक एक सीधी रेखा खींचने का उदाहरण है।
#include <graphics.h>#include <conio.h>int main(void){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");line(100, 100, 200, 200);getch();closegraph();return 0;}
Output:
A graphics window appears showing a straight diagonal line from (100, 100) to (200, 200).
ग्राफिक्स विंडो में (100, 100) से (200, 200) तक एक तिरछी सीधी रेखा दिखाई देगी।
Important Points About line() Function
The
line()function draws a straight line between two specified coordinates.line()फंक्शन दिए गए दो निर्देशांक बिंदुओं के बीच सीधी रेखा खींचता है।The origin
(0, 0)is generally located at the top-left corner of the graphics screen.सामान्यतः ग्राफिक्स स्क्रीन का मूल बिंदु
(0, 0)ऊपरी बाएँ कोने में होता है।The X-coordinate increases from left to right, while the Y-coordinate increases from top to bottom.
X-coordinate बाएँ से दाएँ बढ़ता है, जबकि Y-coordinate ऊपर से नीचे की ओर बढ़ता है।
The
line()function is part of the BGI graphics library and is not a standard C function.line()फंक्शन BGI ग्राफिक्स लाइब्रेरी का हिस्सा है, यह Standard C का फंक्शन नहीं है।
Note for Modern C Compilers
The above program is written for the traditional Turbo C/BGI graphics environment. The graphics.h library and functions such as initgraph(), line() and closegraph() are not provided by standard C compilers such as GCC by default.
ऊपर दिया गया प्रोग्राम पारंपरिक Turbo C/BGI ग्राफिक्स वातावरण के लिए है। graphics.h लाइब्रेरी तथा initgraph(), line() और closegraph() जैसे फंक्शन GCC जैसे आधुनिक C कंपाइलर में डिफॉल्ट रूप से उपलब्ध नहीं होते हैं।
Comments
Post a Comment