← Back to C Course | Chapter 13: Graphics | Lesson 3 of 10

C में Shapes बनाना

आप screen पर circles, rectangles, ellipses और polygons जैसे shapes simple commands से draw कर सकते हैं, shape stamps इस्तेमाल करने जैसा। आप इन्हें fill भी कर सकते हैं।
Syntax
c
circle(x, y, radius);
rectangle(left, top, right, bottom);
ellipse(x, y, start_angle, end_angle, x_radius, y_radius);

Circles Draw करना

circle() एक center coordinate (X, Y) और pixels में एक radius देखकर एक wireframe circle outline draw करता है, सिर्फ boundary trace करते हुए interior fill किए बिना — एक solid disc के लिए आप equal horizontal और vertical radii के साथ इसकी बजाय fillellipse() इस्तेमाल करेंगे।

उदाहरण: Drawing Circles

c
#include <graphics.h>
int main() {
	initgraph(0, 0, "");
	circle(150, 150, 50);
	getch();
	closegraph();
	return 0;
}

Rectangles Draw करना

rectangle() चार coordinates से एक outlined box draw करता है: top-left corner का X और Y, फिर bottom-right corner का X और Y, इसलिए function खुद उन दो corner points के बीच की distance से width और height compute करता है, उन्हें सीधे लेने की बजाय।

उदाहरण: Drawing Rectangles

c
#include <graphics.h>
int main() {
	initgraph(0, 0, "");
	rectangle(50, 50, 200, 150);
	getch();
	closegraph();
	return 0;
}

Ellipses Draw करना

ellipse() एक elliptical arc draw करता है और total आठ parameters लेता है: center coordinates, degrees में एक start और end angle (आपको एक full ellipse की बजाय एक partial arc draw करने देते हुए), और अलग horizontal और vertical radii, जो इसे सिर्फ perfect circles की बजाय true ellipses draw करने देता है।

उदाहरण: Drawing Ellipses

c
#include <graphics.h>
int main() {
	initgraph(0, 0, "");
	ellipse(150, 150, 0, 360, 80, 40);
	getch();
	closegraph();
	return 0;
}

Filled Shapes

fillellipse() और bar() outlines की बजाय solid, filled shapes draw करते हैं — fillellipse() एक elliptical region भरता है, जबकि bar() एक rectangular fill करता है, और bar3d() visible side faces वाले एक pseudo-3D block render करने के लिए एक extra depth parameter से bar() को extend करता है।

उदाहरण: Filled Shapes

c
#include <graphics.h>
int main() {
	initgraph(0, 0, "");
	fillellipse(150, 150, 60, 40);
	bar(50, 50, 150, 100);
	getch();
	closegraph();
	return 0;
}

Polygons Draw करना

drawpoly() और fillpoly() दोनों vertices की तरह आपके दिए (X, Y) coordinate pairs के एक array से arbitrary multi-sided shapes draw करते हैं, drawpoly() सिर्फ polygon का outline trace करता है और fillpoly() additionally इसके interior को current fill style से भरता है।

उदाहरण: Drawing Polygons

c
#include <graphics.h>
int main() {
	initgraph(0, 0, "");
	int points[6] = {100, 50, 150, 150, 50, 150};
	drawpoly(3, points);
	getch();
	closegraph();
	return 0;
}
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. initgraph call करने से पहले shapes draw करना, ताकि कुछ न दिखे।
  2. rectangle(left, top, right, bottom) में arguments का order मिला देना, जो एक गलत या empty shape देता है।
  3. यह उम्मीद करना कि circle(x, y, r) filled होगा, जब यह सिर्फ एक outline draw करता है जब तक आप floodfill या एक fill style भी इस्तेमाल न करें।

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.