15 Graphics Programs in C Programming! 🎨✨
Hello fellow coders! Today, we're diving into the fascinating world of graphics programming in C. Buckle up as we explore 15 amazing programs that will not only sharpen your coding skills but also let your creativity run wild!
1. Drawing a Simple Line 🖋️
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
line(150, 150, 450, 150);
getch();
closegraph();
return 0;
}
In this program, we use the graphics library to draw a line on the screen. The line
function takes the coordinates of the starting and ending points.
2. Creating a Colorful Circle 🌈🔵
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
setcolor(RED);
circle(300, 200, 50);
getch();
closegraph();
return 0;
}
This program introduces color to our canvas. The setcolor
function sets the drawing color, and circle
draws a circle at the specified coordinates.
3. Drawing a Rectangle with Border 📏🖊️
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
rectangle(100, 100, 300, 200);
getch();
closegraph();
return 0;
}
This program utilizes the rectangle
function to draw a rectangle with specified coordinates.
4. Displaying Text on the Screen 📝🖥️
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
outtext("Hello, Graphics Programming!");
getch();
closegraph();
return 0;
}
Here, the outtext
function is used to display text on the screen.
5. Drawing a Circle 🌕🖊️
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
circle(200, 200, 50);
getch();
closegraph();
return 0;
}
This program draws a circle using the circle
function.
6. Drawing Ellipse 🌐🖊️
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
ellipse(200, 200, 0, 360, 100, 50);
getch();
closegraph();
return 0;
}
In this program, the ellipse
function is used to draw an ellipse.
7. Drawing a Line with Dotted Pattern 📏🖊️
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
setlinestyle(DOTTED_LINE, 1, 1);
line(100, 100, 300, 200);
getch();
closegraph();
return 0;
}
This program sets the line style to dotted using setlinestyle
and then draws a line.
8. Filling a Rectangle with Color 📏🌈
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
setfillstyle(SOLID_FILL, GREEN);
bar(100, 100, 300, 200);
getch();
closegraph();
return 0;
}
The setfillstyle
function is used to set the fill pattern, and bar
is used to draw a filled rectangle
9. Drawing a Circle with Color 🌕🖊️
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
setcolor(YELLOW);
circle(200, 200, 50);
getch();
closegraph();
return 0;
}
This program uses setcolor
to set the drawing color and circle
to draw a colored circle.
10. Drawing a Triangle with Gradient Color 📐🌈
c#include <graphics.h>
int main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, NULL);
int points[] = {100, 200, 300, 200, 200, 100, 100, 200};
setfillstyle(INTERLEAVE_FILL, RED);
fillpoly(4, points);
getch();
closegraph();
return 0;
}
Here, fillpoly
is used to draw a filled polygon with a gradient color pattern
Follow us