C Graphics में Colors
In this page:
setcolor(COLOR); // foreground color for lines and outlines
setbkcolor(COLOR); // background color of the window
shape(x, y, ...); // drawn using the current color
Standard Color Constants
BGI graphics library 0 से 15 तक numbered 16 standard color constants define करती है, BLACK, BLUE, GREEN, RED, YELLOW, और WHITE जैसे common colors cover करते हुए, आपको raw RGB values specify करने की ज़रूरत के बिना draw करने के लिए एक fixed, portable palette देते हुए।
उदाहरण: Standard Color Constants
#include <graphics.h>
int main() {
initgraph(0, 0, "");
setcolor(RED);
circle(100, 100, 30);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Foreground Color Set करना
setcolor() lines और shape outlines के लिए इस्तेमाल होने वाला active drawing color उस point से program में आगे बदल देता है; call के बाद draw हुई हर line() या outline shape नया color इस्तेमाल करती है, जबकि पहले draw हुई कोई भी चीज़ जो भी color draw होते समय active था वह रखती है।
उदाहरण: Setting Foreground Color
#include <graphics.h>
int main() {
initgraph(0, 0, "");
setcolor(GREEN);
line(10, 10, 100, 100);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Background Color Set करना
setbkcolor() background color बदलता है जो आपकी drawings के पीछे पूरी graphics window भरता है, setcolor() से अलग जो सिर्फ बाद में draw किए shapes के outline color को affect करता है — background बदलना पूरे canvas को एक साथ recolor करता है।
उदाहरण: Setting Background Color
#include <graphics.h>
int main() {
initgraph(0, 0, "");
setbkcolor(BLUE);
cleardevice();
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Fill Styles और Colors
setfillstyle() control करता है कि closed shapes के interior को कैसे भरा जाए, एक pattern constant (जैसे flat color के लिए SOLID_FILL या crosshatch pattern के लिए HATCH_FILL) को उस color के साथ लेते हुए जिससे भरना है, और बाद में draw किए किसी भी filled shape पर apply होता है।
उदाहरण: Fill Styles and Colors
#include <graphics.h>
int main() {
initgraph(0, 0, "");
setfillstyle(SOLID_FILL, RED);
bar(50, 50, 150, 150);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Shapes को Flood Fill करना
floodfill() एक पूरे enclosed region को current fill style और color से भरता है, आपके उस region के अंदर दिए एक seed coordinate से शुरू करते हुए और specified border color से match करने वाले pixels hit करने तक बाहर फैलते हुए, एक paint bucket tool जैसा।
उदाहरण: Flood Filling Shapes
#include <graphics.h>
int main() {
initgraph(0, 0, "");
circle(100, 100, 50);
setfillstyle(SOLID_FILL, YELLOW);
floodfill(100, 100, WHITE);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
- shape draw करने के बाद color set करना, ताकि यह उस shape को affect न करे।
setcolor(outline और text) कोsetfillstyle(fill) से confuse करना, ताकि fill color न बदले।- एक color constant नाम इस्तेमाल करना जो
graphics.hमें defined नहीं है।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: