rectangle() Function in C Graphics – Syntax and Example
Introduction to rectangle() Function
The rectangle() function is used to draw a rectangle on the graphics screen. It requires four coordinates: the top-left corner (left, top) and the bottom-right corner (right, bottom) of the rectangle. The rectangle() function is available in the traditional BGI (Borland Graphics Interface) graphics library through the graphics.h header file.
rectangle() फंक्शन का उपयोग ग्राफिक्स स्क्रीन पर आयत (Rectangle) बनाने के लिए किया जाता है। इसमें चार निर्देशांकों (Coordinates) की आवश्यकता होती है: आयत का ऊपरी-बायाँ कोना (left, top) तथा निचला-दायाँ कोना (right, bottom)। rectangle() फंक्शन पारंपरिक BGI (Borland Graphics Interface) ग्राफिक्स लाइब्रेरी में उपलब्ध होता है, जिसके लिए graphics.h हेडर फाइल का उपयोग किया जाता है।
Syntax of rectangle() Function
void rectangle(int left, int top, int right, int bottom);Parameters:
left: X-coordinate of the top-left corner.top: Y-coordinate of the top-left corner.right: X-coordinate of the bottom-right corner.bottom: Y-coordinate of the bottom-right corner.
पैरामीटर्स:
left: आयत के ऊपरी-बाएँ कोने का X-coordinate।top: आयत के ऊपरी-बाएँ कोने का Y-coordinate।right: आयत के निचले-दाएँ कोने का X-coordinate।bottom: आयत के निचले-दाएँ कोने का Y-coordinate।
Example: C Program to Draw a Rectangle Using rectangle() Function
The following program demonstrates how to draw a rectangle with its top-left corner at (100, 100) and bottom-right corner at (300, 200).
निम्न प्रोग्राम में (100, 100) को ऊपरी-बायाँ कोना तथा (300, 200) को निचला-दायाँ कोना मानकर एक आयत बनाया गया है।
#include <graphics.h>#include <conio.h>int main(void){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");rectangle(100, 100, 300, 200);getch();closegraph();return 0;}
Output:
A graphics window appears showing a rectangle with a width of 200 coordinate units and a height of 100 coordinate units.
ग्राफिक्स विंडो में एक आयत दिखाई देगा, जिसकी चौड़ाई 200 coordinate units तथा ऊँचाई 100 coordinate units होगी।
Important Points About rectangle() Function
The
rectangle()function draws the outline of a rectangle using four specified coordinates.rectangle()फंक्शन दिए गए चार निर्देशांकों की सहायता से आयत की बाहरी सीमा बनाता है।The first two parameters specify the top-left corner, and the last two parameters specify the bottom-right corner.
पहले दो पैरामीटर ऊपरी-बाएँ कोने तथा अंतिम दो पैरामीटर निचले-दाएँ कोने को दर्शाते हैं।
The rectangle is not filled with color automatically. It draws only the boundary.
rectangle()फंक्शन अपने आप आयत में रंग नहीं भरता है। यह केवल उसकी बाहरी सीमा बनाता है।The
rectangle()function belongs to the BGI graphics library and is not a standard C function.rectangle()फंक्शन 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(), rectangle() and closegraph() are not provided by standard C compilers such as GCC by default.
ऊपर दिया गया प्रोग्राम पारंपरिक Turbo C/BGI ग्राफिक्स वातावरण के लिए है। graphics.h लाइब्रेरी तथा initgraph(), rectangle() और closegraph() जैसे फंक्शन GCC जैसे आधुनिक C कंपाइलर में डिफॉल्ट रूप से उपलब्ध नहीं होते हैं।
Comments
Post a Comment