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 ConstantDescription
EMPTY_FILLEmpty fill pattern
SOLID_FILLSolid color filling
LINE_FILLLine pattern
LTSLASH_FILLLight slash pattern
SLASH_FILLSlash pattern
BKSLASH_FILLBackslash pattern
LTBKSLASH_FILLLight backslash pattern
HATCH_FILLHatch pattern
XHATCH_FILLCross-hatch pattern
INTERLEAVE_FILLInterleaved pattern
WIDE_DOT_FILLWide dot pattern
CLOSE_DOT_FILLClose dot pattern
USER_FILLUser-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:

  1. Yellow rectangle with solid fill.

  2. Red rectangle with line fill.

  3. Green rectangle with hatch fill.

  4. Blue rectangle with cross-hatch fill.

ग्राफिक्स विंडो में चार अलग-अलग फिल पैटर्न वाले आयत दिखाई देंगे:

  1. सॉलिड येलो रंग वाला आयत।

  2. रेड लाइन पैटर्न वाला आयत।

  3. ग्रीन हैच पैटर्न वाला आयत।

  4. ब्लू क्रॉस-हैच पैटर्न वाला आयत।

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

  1. The setfillstyle() function accepts two parameters: fill pattern and fill color.

    setfillstyle() फंक्शन में दो पैरामीटर होते हैं: फिल पैटर्न और फिल कलर।

  2. The selected fill style remains the current fill style until another fill style is selected.

    चुना गया फिल स्टाइल तब तक वर्तमान फिल स्टाइल रहता है, जब तक कोई दूसरा फिल स्टाइल निर्धारित नहीं किया जाता।

  3. The SOLID_FILL pattern is used to fill an area with a solid color.

    SOLID_FILL पैटर्न का उपयोग किसी क्षेत्र को एक समान रंग से भरने के लिए किया जाता है।

  4. The setfillstyle() function is commonly used with floodfill() and bar().

    setfillstyle() फंक्शन का उपयोग सामान्यतः floodfill() और bar() फंक्शन्स के साथ किया जाता है।

  5. 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

Popular posts from this blog

C Language Topics in Hindi and English

Complete C Programming Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025