bar() Function in C Graphics – Syntax and Example
Introduction to bar() Function
The bar() function is used to draw a filled rectangular bar on the graphics screen. It requires four coordinates that specify the top-left and bottom-right corners of the rectangle. The interior of the rectangle is filled using the current fill pattern and fill color. The bar() function is available in the traditional BGI (Borland Graphics Interface) graphics library through the graphics.h header file.
bar() फंक्शन का उपयोग ग्राफिक्स स्क्रीन पर रंग से भरा हुआ आयताकार बार बनाने के लिए किया जाता है। इसमें चार निर्देशांक दिए जाते हैं, जो आयत के ऊपरी-बाएँ तथा निचले-दाएँ कोनों को निर्धारित करते हैं। आयत के अंदर वर्तमान फिल पैटर्न और फिल कलर के अनुसार रंग भरा जाता है। bar() फंक्शन पारंपरिक BGI (Borland Graphics Interface) ग्राफिक्स लाइब्रेरी में उपलब्ध होता है, जिसके लिए graphics.h हेडर फाइल का उपयोग किया जाता है।
Syntax of bar() Function
void bar(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 Filled Bar Using bar() Function
The following program demonstrates how to draw a rectangular bar filled with yellow color using the bar() function.
निम्न प्रोग्राम में bar() फंक्शन की सहायता से पीले रंग से भरा हुआ आयताकार बार बनाने का तरीका समझाया गया है।
#include <graphics.h>#include <conio.h>int main(void){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");/* Set solid yellow fill pattern */setfillstyle(SOLID_FILL, YELLOW);/* Draw a filled rectangular bar */bar(100, 100, 300, 200);getch();closegraph();return 0;}
Output
A graphics window appears showing a solid yellow rectangular bar from coordinate (100, 100) to (300, 200).
ग्राफिक्स विंडो में (100, 100) से (300, 200) तक पीले रंग से भरा हुआ एक आयताकार बार दिखाई देगा।
Difference Between bar() and rectangle() Functions
| bar() Function | rectangle() Function |
|---|---|
| Draws a filled rectangular area. | Draws only the rectangular boundary. |
| Uses the current fill pattern and color. | Uses the current drawing color. |
| Commonly used to draw filled bars. | Commonly used to draw rectangle outlines. |
| bar() फंक्शन | rectangle() फंक्शन |
|---|---|
| रंग से भरा हुआ आयत बनाता है। | केवल आयत की बाहरी सीमा बनाता है। |
| वर्तमान फिल पैटर्न और रंग का उपयोग करता है। | वर्तमान ड्राइंग कलर का उपयोग करता है। |
| भरे हुए बार बनाने के लिए उपयोग होता है। | आयत की बाहरी रेखा बनाने के लिए उपयोग होता है। |
Important Points About bar() Function
The
bar()function requires four parameters to specify the rectangular area.bar()फंक्शन में आयताकार क्षेत्र निर्धारित करने के लिए चार पैरामीटर होते हैं।The rectangle is filled using the current fill pattern and fill color.
आयत के अंदर वर्तमान फिल पैटर्न और फिल कलर के अनुसार रंग भरा जाता है।
The
setfillstyle()function can be used beforebar()to select a particular filling pattern and color.किसी विशेष फिल पैटर्न और रंग का चयन करने के लिए
bar()से पहलेsetfillstyle()फंक्शन का उपयोग किया जा सकता है।Unlike
rectangle(), thebar()function does not draw a separate outline using the current drawing color.rectangle()के विपरीत,bar()फंक्शन वर्तमान ड्राइंग कलर से अलग बाहरी सीमा नहीं बनाता है।The
bar()function belongs to the BGI graphics library and is not a standard C function.bar()फंक्शन 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 bar() and setfillstyle() are not provided by standard C compilers such as GCC by default.
ऊपर दिया गया प्रोग्राम पारंपरिक Turbo C/BGI ग्राफिक्स वातावरण के लिए है। graphics.h लाइब्रेरी तथा bar() और setfillstyle() जैसे फंक्शन GCC जैसे आधुनिक C कंपाइलर में डिफॉल्ट रूप से उपलब्ध नहीं होते हैं।
Comments
Post a Comment