C में Lines और Curves बनाना
In this page:
line(x1, y1, x2, y2); // segment between two points
moveto(x, y); // move cursor without drawing
lineto(x, y); // draw from cursor to (x, y)
arc(x, y, start_angle, end_angle, radius);
Straight Lines Draw करना
line() आपके explicitly specify किए दो coordinates के बीच सीधे एक straight segment draw करता है — एक start point (X1, Y1) और एक end point (X2, Y2) — इसे किसी drawing state track किए बिना screen पर दो known points connect करने का सबसे simple तरीका बनाते हुए।
उदाहरण: Drawing Straight Lines
#include <graphics.h>
int main() {
initgraph(0, 0, "");
line(50, 50, 200, 200);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Current Position से Draw करना
BGI graphics एक implicit 'current position' cursor maintain करता है: moveto() बिना कुछ draw किए उस cursor को reposition करता है, जबकि lineto() cursor जहाँ currently बैठा है वहाँ से एक नए target point तक एक line draw करता है और फिर cursor को उस नए point पर छोड़ देता है, जो segments की एक connected chain draw करने के लिए convenient है।
उदाहरण: Drawing from Current Position
#include <graphics.h>
int main() {
initgraph(0, 0, "");
moveto(50, 50);
lineto(150, 150);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Arcs Draw करना
arc() एक पूरे circle की बजाय इसकी circumference का एक curved segment draw करता है, center coordinates, एक starting angle, एक ending angle (दोनों degrees में), और radius लेते हुए — pie-chart wedges या rounded corners जैसी चीज़ों के लिए useful।
उदाहरण: Drawing Arcs
#include <graphics.h>
int main() {
initgraph(0, 0, "");
arc(150, 150, 0, 180, 50);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Line Styles और Thickness
setlinestyle() बदलता है कि बाद में draw की गई lines कैसी दिखती हैं, SOLID_LINE, DOTTED_LINE, या DASHED_LINE जैसे एक style constant को एक thickness value के साथ accept करते हुए, आपको same drawing में अलग तरह की lines (जैसे grid lines बनाम data lines) visually अलग करने देते हुए।
उदाहरण: Line Styles and Thickness
#include <graphics.h>
int main() {
initgraph(0, 0, "");
setlinestyle(DASHED_LINE, 0, 3);
line(50, 50, 200, 50);
getch();
closegraph();
return 0;
}
Login to try C/C++/Java/PHP code in the editor
Custom Curves Draw करना
एक loop के अंदर एक mathematical formula से computed coordinates पर individual pixels plot करना — उदाहरण के लिए sin() और cos() इस्तेमाल करके एक wave के along points generate करना — आपको smooth curves draw करने देता है जो कोई भी built-in shape function सीधे produce नहीं कर सकता।
उदाहरण: Drawing Custom Curves
#include <graphics.h>
// Include math functions (sqrt, pow, ...)
#include <math.h>
// Program execution starts in main()
int main() {
initgraph(0, 0, "");
// Loop: repeat while the condition holds
for (int x = 0; x < 100; x++) {
// Declare y and set it to 100 + (int)(50 * sin(x * 0.1))
int y = 100 + (int)(50 * sin(x * 0.1));
putpixel(x, y, WHITE);
}
getch();
closegraph();
// Return 0 to signal that the program finished successfully
return 0;
}
Login to try C/C++/Java/PHP code in the editor
line(x1, y1, x2, y2)argument order confuse करना और गलत point पर draw करना।- यह भूल जाना कि y नीचे की ओर बढ़ता है, इसलिए ऊपर जाने वाली एक line नीचे चली जाती है।
arcको radians में angles pass करना, जबarcको degrees चाहिए।
Chapter Quiz — Complete all 10 topics to unlock
0/10 topics done
Complete these topics first: