setfillstyle() Function in C Graphics – Syntax, Patterns and Example
Introduction to setfillstyle() Function
The setfillstyle() function is used to specify the fill pattern and fill color for graphics objects. It determines how an enclosed area will be filled when functions such as floodfill() or bar() are used. The setfillstyle() function is available in the traditional BGI (Borland Graphics Interface) graphics library through the graphics.h header file.
setfillstyle() फंक्शन का उपयोग ग्राफिक्स ऑब्जेक्ट में रंग भरने के लिए फिल पैटर्न (Fill Pattern) तथा फिल कलर (Fill Color) निर्धारित करने के लिए किया जाता है। यह निर्धारित करता है कि floodfill() या bar() जैसे फंक्शन्स द्वारा किसी क्षेत्र में किस प्रकार रंग भरा जाएगा। setfillstyle() फंक्शन पारंपरिक BGI (Borland Graphics Interface) ग्राफिक्स लाइब्रेरी में उपलब्ध होता है, जिसके लिए graphics.h हेडर फाइल का उपयोग किया जाता है।
Syntax of setfillstyle() Function
void setfillstyle(int pattern, int color);Parameters:
pattern: Specifies the fill pattern.color: Specifies the color used for filling.
पैरामीटर्स:
pattern: यह निर्धारित करता है कि क्षेत्र में किस प्रकार का फिल पैटर्न उपयोग होगा।color: यह निर्धारित करता है कि क्षेत्र में कौन-सा रंग भरा जाएगा।
Fill Patterns Available in BGI Graphics
BGI graphics provides several predefined fill patterns. Some commonly used patterns are given below.
BGI ग्राफिक्स में रंग भरने के लिए कई predefined fill patterns उपलब्ध होते हैं। कुछ प्रमुख पैटर्न निम्नलिखित हैं।
| Pattern Constant | Description |
|---|---|
| EMPTY_FILL | Empty fill pattern |
| SOLID_FILL | Solid color filling |
| LINE_FILL | Line pattern |
| LTSLASH_FILL | Light slash pattern |
| SLASH_FILL | Slash pattern |
| BKSLASH_FILL | Backslash pattern |
| LTBKSLASH_FILL | Light backslash pattern |
| HATCH_FILL | Hatch pattern |
| XHATCH_FILL | Cross-hatch pattern |
| INTERLEAVE_FILL | Interleaved pattern |
| WIDE_DOT_FILL | Wide dot pattern |
| CLOSE_DOT_FILL | Close dot pattern |
| USER_FILL | User-defined fill pattern |
Example of setfillstyle() Function
The following statement sets a solid yellow fill pattern.
निम्नलिखित स्टेटमेंट सॉलिड येलो फिल पैटर्न निर्धारित करता है।
setfillstyle(SOLID_FILL, YELLOW);Another example uses a line fill pattern with RED color.
दूसरे उदाहरण में RED रंग के साथ लाइन फिल पैटर्न का उपयोग किया गया है।
setfillstyle(LINE_FILL, RED);C Program to Demonstrate setfillstyle() Function
The following program demonstrates how to draw rectangles with different fill patterns and colors using the setfillstyle() function and bar() function.
निम्न प्रोग्राम में setfillstyle() तथा bar() फंक्शन की सहायता से अलग-अलग फिल पैटर्न और रंगों वाले आयत बनाने का तरीका समझाया गया है।
#include <graphics.h>#include <conio.h>int main(void){int gd = DETECT, gm;initgraph(&gd, &gm, "C:\\TC\\BGI");/* Solid yellow fill */setfillstyle(SOLID_FILL, YELLOW);bar(50, 50, 200, 120);/* Red line fill */setfillstyle(LINE_FILL, RED);bar(250, 50, 400, 120);/* Green hatch fill */setfillstyle(HATCH_FILL, GREEN);bar(50, 160, 200, 230);/* Blue cross-hatch fill */setfillstyle(XHATCH_FILL, BLUE);bar(250, 160, 400, 230);getch();closegraph();return 0;}
Output
A graphics window displays four filled rectangular areas:
Yellow rectangle with solid fill.
Red rectangle with line fill.
Green rectangle with hatch fill.
Blue rectangle with cross-hatch fill.
ग्राफिक्स विंडो में चार अलग-अलग फिल पैटर्न वाले आयत दिखाई देंगे:
सॉलिड येलो रंग वाला आयत।
रेड लाइन पैटर्न वाला आयत।
ग्रीन हैच पैटर्न वाला आयत।
ब्लू क्रॉस-हैच पैटर्न वाला आयत।
Difference Between setfillstyle() and floodfill() Functions
| setfillstyle() | floodfill() |
|---|---|
| Sets the fill pattern and color. | Fills an enclosed area. |
| It does not fill an area by itself. | It performs the filling operation. |
| Takes two parameters. | Takes three parameters. |
setfillstyle() | floodfill() |
|---|---|
| फिल पैटर्न और रंग निर्धारित करता है। | बंद क्षेत्र में रंग भरता है। |
| यह अपने आप किसी क्षेत्र में रंग नहीं भरता है। | यह वास्तव में रंग भरने का कार्य करता है। |
| इसमें दो पैरामीटर होते हैं। | इसमें तीन पैरामीटर होते हैं। |
Important Points About setfillstyle() Function
The
setfillstyle()function accepts two parameters: fill pattern and fill color.setfillstyle()फंक्शन में दो पैरामीटर होते हैं: फिल पैटर्न और फिल कलर।The selected fill style remains the current fill style until another fill style is selected.
चुना गया फिल स्टाइल तब तक वर्तमान फिल स्टाइल रहता है, जब तक कोई दूसरा फिल स्टाइल निर्धारित नहीं किया जाता।
The
SOLID_FILLpattern is used to fill an area with a solid color.SOLID_FILLपैटर्न का उपयोग किसी क्षेत्र को एक समान रंग से भरने के लिए किया जाता है।The
setfillstyle()function is commonly used withfloodfill()andbar().setfillstyle()फंक्शन का उपयोग सामान्यतःfloodfill()औरbar()फंक्शन्स के साथ किया जाता है।The
setfillstyle()function belongs to the BGI graphics library and is not a standard C function.setfillstyle()फंक्शन 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 setfillstyle() and bar() are not provided by standard C compilers such as GCC by default.
ऊपर दिया गया प्रोग्राम पारंपरिक Turbo C/BGI ग्राफिक्स वातावरण के लिए है। graphics.h लाइब्रेरी तथा setfillstyle() और bar() जैसे फंक्शन GCC जैसे आधुनिक C कंपाइलर में डिफॉल्ट रूप से उपलब्ध नहीं होते हैं।
Comments
Post a Comment