Computer Graphics Programs (C Language)
Program to Draw a Flag
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(WHITE);
rectangle(100, 100, 300, 200);
line(200, 100, 200, 200);
getch();
closegraph();
}
Output:-
Program to Make a Smiley Face
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circle(200, 200, 50);
circle(185, 190, 5);
circle(215, 190, 5);
arc(200, 210, 200, 340, 20);
getch();
closegraph();
}
Output:-
Computer Graphics Programs (C Language)
Program to Draw a Simple House
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
rectangle(100, 150, 200, 250);
line(100, 150, 150, 100);
line(150, 100, 200, 150);
getch();
closegraph();
}
Output:-
Program to Create a Simple Car
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
rectangle(100, 200, 250, 250);
rectangle(150, 150, 200, 200);
circle(120, 260, 10);
circle(230, 260, 10);
getch();
closegraph();
}
Output:-
Computer Graphics Programs (C Language)
Program to Draw a Tree
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
rectangle(190, 200, 210, 300);
circle(200, 180, 30);
getch();
closegraph();
}
Output:-
Program to Draw a Robot Face
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
rectangle(150, 100, 250, 200);
circle(170, 130, 10);
circle(230, 130, 10);
line(180, 170, 220, 170);
getch();
closegraph();
}
Output:-
Computer Graphics Programs (C Language)
Program to Draw a Flower
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circle(200, 200, 10);
for (int i = 0; i < 360; i += 45)
circle(200 + 30 * cos(i * 3.14 / 180), 200 + 30 * sin(i * 3.14 / 180), 10);
getch();
closegraph();
}
Output:-
Program to Create a Moving Ball Animation
Code:-
#include <graphics.h>
#include <dos.h>
void main() {
int gd = DETECT, gm, i;
initgraph(&gd, &gm, "");
for (i = 0; i < 400; i += 5) {
cleardevice();
circle(50 + i, 100, 20);
delay(100);
}
getch();
closegraph();
}
Output:-
Computer Graphics Programs (C Language)
Program to Draw a Kite
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
line(200, 100, 150, 200);
line(200, 100, 250, 200);
line(150, 200, 200, 300);
line(250, 200, 200, 300);
getch();
closegraph();
}
Output:-
Program to Create a Pattern of Circles
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm, i;
initgraph(&gd, &gm, "");
for (i = 0; i < 360; i += 30)
circle(200 + 50 * cos(i * 3.14 / 180), 200 + 50 * sin(i * 3.14 / 180), 20);
getch();
closegraph();
}
Output:-
Computer Graphics Programs (C Language)
Program to Draw Indian Flag Layout
Code:-
#include <graphics.h>
#include <conio.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
setcolor(WHITE);
rectangle(100, 100, 300, 180);
setfillstyle(SOLID_FILL, COLOR(255, 165, 0));
floodfill(101, 110, WHITE);
setfillstyle(SOLID_FILL, WHITE);
floodfill(101, 135, WHITE);
setfillstyle(SOLID_FILL, GREEN);
floodfill(101, 165, WHITE);
getch();
closegraph();
}
Output:-
Program to Draw a Star
Code:-
#include <graphics.h>
#include <math.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
line(100, 150, 150, 50);
line(150, 50, 200, 150);
line(200, 150, 100, 100);
line(100, 100, 200, 100);
line(200, 100, 100, 150);
getch();
closegraph();
}
Output:-
Computer Graphics Programs (C Language)
Program to Draw a Smiling Face with Hat
Code:-
#include <graphics.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circle(200, 200, 50);
circle(185, 190, 5);
circle(215, 190, 5);
arc(200, 210, 200, 340, 20);
rectangle(170, 150, 230, 170);
rectangle(180, 130, 220, 150);
getch();
closegraph();
}
Output:-
Program to Draw a Sun
Code:-
#include <graphics.h>
#include <math.h>
void main() {
int gd = DETECT, gm, i;
initgraph(&gd, &gm, "");
circle(200, 200, 30);
for (i = 0; i < 360; i += 30)
line(200, 200, 200 + 50 * cos(i * 3.14 / 180), 200 + 50 * sin(i * 3.14 / 180));
getch();
closegraph();
}
Output:-
Computer Graphics Programs (C Language)
Program to Draw a Boat
Code:-
#include <graphics.h>
void main() {
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
line(100, 250, 300, 250);
line(100, 250, 150, 300);
line(150, 300, 250, 300);
line(250, 300, 300, 250);
line(200, 250, 200, 150);
line(200, 150, 250, 200);
line(250, 200, 200, 200);
getch();
closegraph();
}
Output:-