In this tutorial, we will learn how to create a simple graphics program in C++ that shows a man and his child standing in the rain with an umbrella. This program is created using basic graphics functions like line(), circle(), and ellipse().
First, we need to initialize the graphics mode using the initgraph() function from the graphics library. We then set the background color of the window using the setbkcolor() function. After that, we can start drawing the graphics.
To draw the man, we can use the line() function to draw lines for the body, arms, and legs. We can also use the circle() function to draw the head. For the child, we can use similar line() and circle() functions to draw the body and head.
To draw the umbrella, we can use the ellipse() function to draw a circle for the top of the umbrella and then use the line() function to draw the handle.
Finally, we can use the outtextxy() function to display the message "Stay Dry" on the screen.
Overall, this program is a fun and easy way to learn about basic graphics functions in C++ and to create a simple graphics program that can be customized and expanded upon.
Program :
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
void main()
{
clrscr();
int gdriver = DETECT,gmode,i,x=850,y=800;
initgraph(&gdriver,&gmode,"C:\\TC\\BGI");
circle(240,340,20);//man head
line(240,360,240,400);//man body
line(240,400,220,470);//man left leg
line(240,400,260,470);//man right leg
circle(290,380,15);//boy head
line(290,395,290,425);//boy body
line(290,425,280,470);//boy left leg
line(290,425,305,470);//boy right leg
line(240,380,260,380);//man right hand
line(300,410,280,410);//boy left hand
line(260,380,280,410);
line(240,380,215,390);//man left hand
line(215,390,230,365);//man left hand
line(300,410,315,420);//boy right hand
line(230,365,230,310);//hundle
line(150,310,310,310);
line(0,470,630,470);//ground
ellipse(230,310,0,180,80,80);
ellipse(225,360,180,360,5,5);
for(i=0;i<500;i++){
outtextxy(random(x),random(y),"`");
delay(20);
}
getch();
}
Output :
0 Comments