setcolor(), setbkcolor() and floodfill() Functions in C Graphics

1. setcolor() Function in C Graphics

The setcolor() function is used to change the current drawing color. It sets the color that will be used for drawing graphics objects such as lines, circles, rectangles and other shapes.

The default drawing color in BGI graphics is WHITE.

setcolor() फंक्शन का उपयोग वर्तमान ड्राइंग कलर को बदलने के लिए किया जाता है। इसका उपयोग लाइन, सर्कल, रेक्टेंगल तथा अन्य ग्राफिक्स आकृतियों को बनाने के लिए किया जाता है।

BGI ग्राफिक्स में डिफॉल्ट ड्राइंग कलर WHITE (सफेद) होता है।

Syntax

void setcolor(int color);

Example

setcolor(RED);

OR

setcolor(4);

Both statements set the current drawing color to RED.

दोनों स्टेटमेंट वर्तमान ड्राइंग कलर को RED (लाल) कर देते हैं।

2. setbkcolor() Function in C Graphics

The setbkcolor() function is used to change the current background color of the graphics screen. The default background color in BGI graphics is BLACK.

setbkcolor() फंक्शन का उपयोग ग्राफिक्स स्क्रीन के वर्तमान बैकग्राउंड कलर को बदलने के लिए किया जाता है। BGI ग्राफिक्स में डिफॉल्ट बैकग्राउंड कलर BLACK (काला) होता है।

Syntax

void setbkcolor(int color);

Example

setbkcolor(YELLOW);

OR

setbkcolor(14);

Both statements change the background color to YELLOW.

दोनों स्टेटमेंट बैकग्राउंड कलर को YELLOW (पीला) कर देते हैं।

3. floodfill() Function in C Graphics

The floodfill() function is used to fill an enclosed area with the current fill pattern and fill color. It starts filling from a specified point inside the enclosed area and continues until it reaches the specified boundary color.

floodfill() फंक्शन का उपयोग किसी बंद क्षेत्र (Enclosed Area) में वर्तमान फिल पैटर्न और फिल कलर की सहायता से रंग भरने के लिए किया जाता है। यह दिए गए बिंदु से रंग भरना शुरू करता है और निर्धारित बॉर्डर कलर तक पहुँचने पर रुक जाता है।

Syntax

void floodfill(int x, int y, int border);

Parameters:

  • x: X-coordinate of the starting point inside the enclosed area.

  • y: Y-coordinate of the starting point inside the enclosed area.

  • border: Boundary color of the enclosed area.

पैरामीटर्स:

  • x: बंद क्षेत्र के अंदर स्थित शुरुआती बिंदु का X-coordinate।

  • y: बंद क्षेत्र के अंदर स्थित शुरुआती बिंदु का Y-coordinate।

  • border: बंद क्षेत्र की बाहरी सीमा का रंग (Border Color)।

Example

floodfill(100, 100, RED);

This statement fills the enclosed area starting from coordinate (100, 100) and stops when it reaches the RED boundary.

यह स्टेटमेंट (100, 100) निर्देशांक से बंद क्षेत्र में रंग भरना शुरू करता है तथा RED रंग की सीमा मिलने पर रुक जाता है।

Colors Available in BGI Graphics

The following are the commonly used predefined color constants in BGI graphics.

BGI ग्राफिक्स में निम्नलिखित predefined color constants का उपयोग किया जाता है।

Color ConstantColor NumberColor
BLACK0Black
BLUE1Blue
GREEN2Green
CYAN3Cyan
RED4Red
MAGENTA5Magenta
BROWN6Brown
LIGHTGRAY7Light Gray
DARKGRAY8Dark Gray
LIGHTBLUE9Light Blue
LIGHTGREEN10Light Green
LIGHTCYAN11Light Cyan
LIGHTRED12Light Red
LIGHTMAGENTA13Light Magenta
YELLOW14Yellow
WHITE15White

C Program to Demonstrate setcolor(), setbkcolor() and floodfill() Functions

The following program demonstrates how to change the drawing color, change the background color and fill a circle with a selected color using these graphics functions.

निम्न प्रोग्राम में इन ग्राफिक्स फंक्शन्स की सहायता से ड्राइंग कलर बदलने, बैकग्राउंड कलर बदलने तथा सर्कल के अंदर चुने हुए रंग को भरने का तरीका समझाया गया है।

#include <graphics.h>
#include <conio.h>
int main(void)
{
int gd = DETECT, gm;
initgraph(&gd, &gm, "C:\\TC\\BGI");
/* Change background color */
setbkcolor(BLUE);
/* Set circle boundary color */
setcolor(RED);
/* Draw a circle */
circle(200, 200, 80);
/* Set fill pattern and fill color */
setfillstyle(SOLID_FILL, YELLOW);
/* Fill the circle */
floodfill(200, 200, RED);
getch();
closegraph();
return 0;
}

Output

A graphics window displays a RED outlined circle filled with YELLOW color on a BLUE background.

ग्राफिक्स विंडो में BLUE बैकग्राउंड पर RED बॉर्डर वाला एक सर्कल दिखाई देगा, जिसके अंदर YELLOW रंग भरा होगा।

Important Points About These Functions

  1. setcolor() changes the current drawing color used by graphics drawing functions.

    setcolor() ग्राफिक्स ड्राइंग फंक्शन्स द्वारा उपयोग किए जाने वाले वर्तमान ड्राइंग कलर को बदलता है।

  2. setbkcolor() changes the background color of the graphics screen.

    setbkcolor() ग्राफिक्स स्क्रीन के बैकग्राउंड कलर को बदलता है।

  3. floodfill() fills an enclosed area using the current fill pattern and fill color.

    floodfill() वर्तमान फिल पैटर्न और फिल कलर की सहायता से बंद क्षेत्र में रंग भरता है।

  4. The starting point of floodfill() must be inside the enclosed area.

    floodfill() का शुरुआती बिंदु बंद क्षेत्र के अंदर होना चाहिए।

  5. The specified boundary color must correctly match the boundary pixels. If the boundary has gaps, filling may spread outside the intended area.

    दिया गया बॉर्डर कलर क्षेत्र की सीमा के पिक्सेल के रंग से मेल खाना चाहिए। यदि सीमा में कहीं खाली स्थान है, तो रंग निर्धारित क्षेत्र के बाहर भी फैल सकता है।

  6. The setfillstyle() function is used to specify the fill pattern and fill color.

    setfillstyle() फंक्शन का उपयोग फिल पैटर्न तथा फिल कलर निर्धारित करने के लिए किया जाता है।

  7. These functions belong to the traditional BGI graphics library and are not standard C functions.

    ये सभी फंक्शन पारंपरिक 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 setcolor(), setbkcolor(), setfillstyle() and floodfill() are not provided by standard C compilers such as GCC by default.

ऊपर दिया गया प्रोग्राम पारंपरिक Turbo C/BGI ग्राफिक्स वातावरण के लिए है। graphics.h लाइब्रेरी तथा setcolor(), setbkcolor(), setfillstyle() और floodfill() जैसे फंक्शन 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