-
Notifications
You must be signed in to change notification settings - Fork 0
/
RAINMAN.CPP
165 lines (150 loc) · 3.88 KB
/
RAINMAN.CPP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/* This Code is Created by Mehul Patni using turbo c++
Last Update date - 16/05/2019
This is a c++ code which is based upon the concept of Kinematics "Rain Man Problem".
It helps students to visualize the problem and get the accurate solution in seconds.
*/
#include<stdio.h>
#include<graphics.h>
#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<stdlib.h>
#define ScreenWidth getmaxx()
#define ScreenHeight getmaxy()
#define GroundY ScreenHeight*0.8
#include<time.h>
#include<dos.h>
#include<math.h>
#define PI 3.14159265
int ldisp=0;
void DrawManAndUmbrella(int x,int ldisp, int theta)
{
//head
circle(x,GroundY-90,10);
line(x,GroundY-80,x,GroundY-30);
//hand
line(x,GroundY-70,x+10,GroundY-60);
line(x,GroundY-65,x+10,GroundY-55);
line(x+10,GroundY-60,x+20,GroundY-70);
line(x+10,GroundY-55,x+20,GroundY-70);
//legs
line(x,GroundY-30,x+ldisp,GroundY);
line(x,GroundY-30,x-ldisp,GroundY);
//umbrella
if(theta >= 0){
pieslice(x+20-abs(50*sin(theta)) , GroundY-70-abs(50*cos(theta)),theta,180+theta,40);
line( x+20-abs(50*sin(theta)) , GroundY-70-abs(50*cos(theta)) , x+20 , GroundY-70);
}
else{
pieslice(x+20-50*sin(theta) , GroundY-70-50*cos(theta),360+theta,360,40);
pieslice(x+20-50*sin(theta) , GroundY-70-50*cos(theta),0,180+theta,40);
line( x+20-50*sin(theta) , GroundY-70-50*cos(theta) , x+20 , GroundY-70);
}
}
void Rain(int x, int RX, int RY, int theta)
{
int i,rx,ry;
for(i=0;i<400;i++)
{
//Random Rain On Screen
rx=rand() % ScreenWidth;
ry=rand() % ScreenHeight;
if(ry<GroundY-RY)
{
if(ry<GroundY-120 || (ry>GroundY-120 && (rx<x-20-abs(50*sin(abs(theta))) || rx>x+20+abs(50*sin(abs(theta))))))
line(rx,ry,rx+RX,ry+RY);
}
}
}
void printLetter() // Screen 1
{
cout<<"\n\n\n\n\n\n\n\n";
for (int i =0; i<7 ; i++)
{
cout<<"\t\t ";
// To Print R Letter
for(int j =0; j<7; j++)
{
if(i == 0 || i ==2 || j ==0 || j == 6 && i <= 2 || j == i-1 && i >= 2)
cout<<"*";
else
cout<<" ";
delay(50);
}
cout<<" \t";
// To Print M Letter
for(j =0; j<7; j++)
{
if(i == j && i<=3 || j==6-i && i<=3 || j==0 || j==6)
cout<<"*";
else
cout<<" ";
delay(100);
}
cout<<" \t";
// To print P Letter
for(j =0; j<7; j++)
{
if(i == 0 || i==2 || j==0 || j==6 && i<=2)
cout<<"*";
else
cout<<" ";
delay(50);
}
cout<<endl;
}
}
void main()
{
int gd=DETECT,gm,x=0;
//Change BGI directory according to yours
initgraph(&gd,&gm,"C:\\TurboC3\\BGI");
printLetter();
sleep(2);
clrscr();
cleardevice();
int rmx,rmy,mx,rm;
float rv,theta,fi;
cout<<"\n\n\n\t***************Rain Man Problem***************"; //Ask Question & Get Solution
cout<<endl;
cout<<"\n\nEnter Velocity of rain in x Direction w.r.t man --> ";
cin>>rmx;
cout<<"Enter Velocity of rain in y Direction w.r.t man --> ";
cin>>rmy;
cout<<"Enter velocity of Man in x Direction --> ";
cin>>mx;
// Calculating Velocity of Actual Rain and Angle of inclinatiion
rm = mx + rmx;
rv = sqrt( abs(rm)*abs(rm) + rmy*rmy );
theta =atan2(rm,rmy) * 180/PI;
cout<<"\nTherefore, Velocity of rain is --> "<<rv;
cout<<"\nAngle forming with vertical(Y) axis is --> "<<theta;
fi = 180*atan2(rmx,rmy)/PI;
delay(1000);
clrscr();
cleardevice();
cout<<"\nActual Seen :- ";
delay(1000);
cleardevice();
while(!kbhit() && mx>0) // Screen 3
{
line(0,GroundY,ScreenWidth,GroundY);
Rain(x,rm,rmy,theta);
ldisp=(ldisp+mx)%30;
DrawManAndUmbrella(x,ldisp,theta);
delay(75);
cleardevice();
x=(x+5)%ScreenWidth;
}
clrscr();
cleardevice();
cout<<"\nView w.r.t Man :- "; // Screen 4
delay(1000);
cleardevice();
x = ScreenWidth/2;
line(0,GroundY,ScreenWidth,GroundY);
Rain(x,rmx,rmy,fi);
DrawManAndUmbrella(x,ldisp,fi);
sleep(4);
getch();
}