Additional Drawing Functions in C Graphics – Syntax and Examples

The BGI graphics library provides several additional drawing functions that help programmers create different shapes, lines, polygons and filled objects on the graphics screen. In this post, we will learn about moveto(), lineto(), drawpoly(), fillpoly(), pieslice(), sector(), fillellipse() and bar3d() functions.

BGI ग्राफिक्स लाइब्रेरी में कई अतिरिक्त drawing functions उपलब्ध होते हैं, जिनकी सहायता से ग्राफिक्स स्क्रीन पर अलग-अलग आकृतियाँ, लाइनें, पॉलीगॉन तथा भरे हुए ऑब्जेक्ट बनाए जा सकते हैं। इस पोस्ट में हम moveto(), lineto(), drawpoly(), fillpoly(), pieslice(), sector(), fillellipse() तथा bar3d() फंक्शन के बारे में जानेंगे।

1. moveto() Function

The moveto() function is used to move the current graphics position to a specified X and Y coordinate without drawing a line.

moveto() फंक्शन का उपयोग बिना कोई लाइन बनाए वर्तमान ग्राफिक्स पोजीशन को निर्धारित X तथा Y कोऑर्डिनेट पर ले जाने के लिए किया जाता है।

Syntax:

void moveto(int x, int y);

Example:

moveto(100, 100);

This statement moves the current graphics position to (100, 100).

यह स्टेटमेंट वर्तमान ग्राफिक्स पोजीशन को (100, 100) पर ले जाता है।

2. lineto() Function

The lineto() function draws a line from the current graphics position to the specified X and Y coordinates. After drawing the line, the current position is updated to the new endpoint.

lineto() फंक्शन वर्तमान ग्राफिक्स पोजीशन से निर्धारित X तथा Y कोऑर्डिनेट तक लाइन बनाता है। लाइन बनाने के बाद वर्तमान पोजीशन नई अंतिम पोजीशन पर अपडेट हो जाती है।

Syntax:

void lineto(int x, int y);

Example:

moveto(100, 100);
lineto(300, 200);

The above statements draw a line from (100, 100) to (300, 200).

उपरोक्त स्टेटमेंट (100, 100) से (300, 200) तक एक लाइन बनाते हैं।

3. drawpoly() Function

The drawpoly() function is used to draw a polygon by connecting a series of points. The first point must be repeated at the end of the coordinate array to close the polygon.

drawpoly() फंक्शन का उपयोग कई पॉइंट्स को आपस में जोड़कर पॉलीगॉन बनाने के लिए किया जाता है। पॉलीगॉन को बंद करने के लिए coordinate array में पहले पॉइंट को अंतिम पॉइंट के रूप में दोबारा देना आवश्यक होता है।

Syntax:

void drawpoly(int numpoints, int *polypoints);

Parameters:

  • numpoints: Number of coordinate pairs.

  • polypoints: Array containing X and Y coordinates.

पैरामीटर्स:

  • numpoints: कोऑर्डिनेट पेयर्स की संख्या।

  • polypoints: X तथा Y कोऑर्डिनेट रखने वाला array।

Example:

int points[] = {
100, 100,
200, 50,
300, 100,
250, 200,
150, 200,
100, 100
};
drawpoly(6, points);

This program draws a closed polygon using six coordinate pairs.

यह प्रोग्राम छह coordinate pairs का उपयोग करके एक बंद पॉलीगॉन बनाता है।

4. fillpoly() Function

The fillpoly() function is used to draw a polygon and fill its interior using the currently selected fill pattern and color.

fillpoly() फंक्शन का उपयोग पॉलीगॉन बनाने तथा उसके अंदर वर्तमान fill pattern और color के अनुसार रंग भरने के लिए किया जाता है।

Syntax:

void fillpoly(int numpoints, int *polypoints);

Example:

int points[] = {
100, 100,
200, 50,
300, 100,
250, 200,
150, 200,
100, 100
};
setfillstyle(SOLID_FILL, YELLOW);
fillpoly(6, points);

The above example draws a polygon and fills it with yellow color.

उपरोक्त उदाहरण में एक पॉलीगॉन बनाया जाता है तथा उसके अंदर पीला रंग भरा जाता है।

5. pieslice() Function

The pieslice() function is used to draw and fill a pie-shaped portion of a circle between two specified angles.

pieslice() फंक्शन का उपयोग दो निर्धारित एंगल के बीच सर्कल के एक हिस्से को पाई के आकार में बनाने तथा उसमें रंग भरने के लिए किया जाता है।

Syntax:

void pieslice(int x, int y, int startangle,
int endangle, int radius);

Parameters:

  • x, y: Center coordinates.

  • startangle: Starting angle.

  • endangle: Ending angle.

  • radius: Radius of the circle.

पैरामीटर्स:

  • x, y: सर्कल के केंद्र के कोऑर्डिनेट।

  • startangle: प्रारंभिक एंगल।

  • endangle: अंतिम एंगल।

  • radius: सर्कल की त्रिज्या।

Example:

setfillstyle(SOLID_FILL, RED);
pieslice(200, 200, 0, 90, 100);

This statement draws and fills a quarter-circle pie slice.

यह स्टेटमेंट सर्कल के एक चौथाई हिस्से को पाई के आकार में बनाकर उसमें रंग भरता है।

6. sector() Function

The sector() function is used to draw and fill a sector of an ellipse between two specified angles.

sector() फंक्शन का उपयोग दो निर्धारित एंगल के बीच एलिप्स के एक हिस्से को बनाने तथा उसमें रंग भरने के लिए किया जाता है।

Syntax:

void sector(int x, int y, int startangle,
int endangle, int xradius, int yradius);

Parameters:

  • x, y: Center coordinates.

  • startangle: Starting angle.

  • endangle: Ending angle.

  • xradius: Horizontal radius.

  • yradius: Vertical radius.

पैरामीटर्स:

  • x, y: एलिप्स के केंद्र के कोऑर्डिनेट।

  • startangle: प्रारंभिक एंगल।

  • endangle: अंतिम एंगल।

  • xradius: क्षैतिज त्रिज्या।

  • yradius: ऊर्ध्वाधर त्रिज्या।

Example:

setfillstyle(SOLID_FILL, GREEN);
sector(250, 200, 0, 180, 120, 70);

This statement draws and fills an elliptical sector.

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

7. fillellipse() Function

The fillellipse() function is used to draw a filled ellipse using the specified center coordinates and horizontal and vertical radii.

fillellipse() फंक्शन का उपयोग निर्धारित केंद्र कोऑर्डिनेट तथा क्षैतिज और ऊर्ध्वाधर त्रिज्या की सहायता से भरा हुआ एलिप्स बनाने के लिए किया जाता है।

Syntax:

void fillellipse(int x, int y, int xradius, int yradius);

Parameters:

  • x, y: Center coordinates.

  • xradius: Horizontal radius.

  • yradius: Vertical radius.

पैरामीटर्स:

  • x, y: एलिप्स के केंद्र के कोऑर्डिनेट।

  • xradius: क्षैतिज त्रिज्या।

  • yradius: ऊर्ध्वाधर त्रिज्या।

Example:

setcolor(WHITE);
setfillstyle(SOLID_FILL, BLUE);
fillellipse(250, 200, 100, 50);

This statement draws a filled blue ellipse.

यह स्टेटमेंट नीले रंग का भरा हुआ एलिप्स बनाता है।

8. bar3d() Function

The bar3d() function is used to draw a three-dimensional rectangular bar. It accepts the coordinates of the rectangle, depth of the 3D effect and a parameter that controls whether the top face is drawn.

bar3d() फंक्शन का उपयोग तीन-आयामी आयताकार बार बनाने के लिए किया जाता है। इसमें आयत के कोऑर्डिनेट, 3D प्रभाव की गहराई तथा एक पैरामीटर दिया जाता है जो यह निर्धारित करता है कि ऊपर वाला भाग बनाया जाएगा या नहीं।

Syntax:

void bar3d(int left, int top, int right, int bottom,
int depth, int topflag);

Parameters:

  • left: Left coordinate.

  • top: Top coordinate.

  • right: Right coordinate.

  • bottom: Bottom coordinate.

  • depth: Depth of the 3D bar.

  • topflag: If non-zero, the top face is drawn; if zero, it is not drawn.

पैरामीटर्स:

  • left: बाईं ओर का कोऑर्डिनेट।

  • top: ऊपर का कोऑर्डिनेट।

  • right: दाईं ओर का कोऑर्डिनेट।

  • bottom: नीचे का कोऑर्डिनेट।

  • depth: 3D बार की गहराई।

  • topflag: यदि इसका मान non-zero है तो ऊपर वाला भाग बनाया जाता है, अन्यथा नहीं।

Example:

setfillstyle(SOLID_FILL, CYAN);
bar3d(100, 100, 250, 200, 30, 1);

This statement draws a three-dimensional rectangular bar with a depth of 30 pixels and a visible top face.

यह स्टेटमेंट 30 पिक्सेल की गहराई तथा दिखाई देने वाले ऊपरी भाग के साथ तीन-आयामी आयताकार बार बनाता है।

Combined C Program Using Additional Drawing Functions

The following program demonstrates several additional drawing functions in a single graphics window.

निम्न प्रोग्राम में एक ही ग्राफिक्स विंडो में कई अतिरिक्त drawing functions का उपयोग प्रदर्शित किया गया है।

#include <graphics.h>
#include <conio.h>
int main(void)
{
int gd = DETECT, gm;
int points[] = {
100, 100,
150, 50,
200, 100,
175, 150,
125, 150,
100, 100
};
initgraph(&gd, &gm, "C:\\TC\\BGI");
/* moveto() and lineto() */
setcolor(WHITE);
moveto(50, 50);
lineto(150, 50);
/* drawpoly() */
drawpoly(6, points);
/* fillpoly() */
setfillstyle(SOLID_FILL, YELLOW);
fillpoly(6, points);
/* pieslice() */
setfillstyle(SOLID_FILL, RED);
pieslice(300, 100, 0, 90, 50);
/* sector() */
setfillstyle(SOLID_FILL, GREEN);
sector(450, 100, 0, 180, 60, 35);
/* fillellipse() */
setfillstyle(SOLID_FILL, BLUE);
fillellipse(150, 280, 60, 35);
/* bar3d() */
setfillstyle(SOLID_FILL, CYAN);
bar3d(300, 230, 420, 300, 25, 1);
getch();
closegraph();
return 0;
}

Output:

The graphics window displays lines, a polygon, a pie slice, an elliptical sector, a filled ellipse and a 3D bar.

ग्राफिक्स विंडो में लाइनें, पॉलीगॉन, पाई स्लाइस, एलिप्सिकल सेक्टर, भरा हुआ एलिप्स तथा 3D बार दिखाई देंगे।

Important Points

  1. moveto() changes the current graphics position without drawing a line.

    moveto() बिना लाइन बनाए वर्तमान ग्राफिक्स पोजीशन बदलता है।

  2. lineto() draws a line from the current position to the specified position.

    lineto() वर्तमान पोजीशन से निर्धारित पोजीशन तक लाइन बनाता है।

  3. drawpoly() draws the outline of a polygon, whereas fillpoly() also fills its interior.

    drawpoly() पॉलीगॉन की बाहरी रेखा बनाता है, जबकि fillpoly() उसके अंदर रंग भी भरता है।

  4. pieslice() draws a circular pie slice, whereas sector() draws an elliptical sector.

    pieslice() सर्कल का पाई स्लाइस बनाता है, जबकि sector() एलिप्स का सेक्टर बनाता है।

  5. fillellipse() draws a filled ellipse.

    fillellipse() भरा हुआ एलिप्स बनाता है।

  6. bar3d() draws a three-dimensional rectangular bar.

    bar3d() तीन-आयामी आयताकार बार बनाता है।

  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 programs are designed for the traditional Turbo C/BGI graphics environment. The graphics.h library and these graphics functions are not available by default in modern C compilers such as GCC.

ऊपर दिए गए प्रोग्राम पारंपरिक Turbo C/BGI ग्राफिक्स वातावरण के लिए बनाए गए हैं। graphics.h लाइब्रेरी तथा ये ग्राफिक्स फंक्शन GCC जैसे आधुनिक C कंपाइलर में डिफॉल्ट रूप से उपलब्ध नहीं होते हैं।

Comments

Popular posts from this blog

Complete C Programming Language Syllabus | Advanced C Roadmap for Students

Top High-Paying Tech Skills to Learn in 2025

C Programming for Finance: A Powerful Tool for Financial Modeling and Analysis