-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolar system.cpp
More file actions
221 lines (189 loc) · 4.59 KB
/
solar system.cpp
File metadata and controls
221 lines (189 loc) · 4.59 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
// C program to draw solar system using
// computer graphics
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <math.h>
#include <stdio.h>
// Function to manipulates the position
// of planets on the orbit
void planetMotion(int xrad, int yrad,
int midx, int midy,
int x[70], int y[70])
{
int i, j = 0;
// Positions of planets in their
// corresponding orbits
for (i = 360; i > 0; i = i - 6) {
x[j] = midx - (xrad * cos((i * 3.14) / 180));
y[j++] = midy - (yrad * sin((i * 3.14) / 180));
}
return;
}
// Driver Code
int main()
{
// Initialize graphic driver
int gdriver = DETECT, gmode, err;
int i = 0, midx, midy;
int xrad[9], yrad[9], x[9][70], y[9][70];
int pos[9], planet[9], tmp;
// Initialize graphics mode by
// passing the three arguments
// to initgraph()
// &gdriver is the address of gdriver
// variable, &gmode is the address of
// gmode and "C:\\Turboc3\\BGI" is the
// directory path where BGI files
// are stored
initgraph(&gdriver, &gmode, "");
err = graphresult();
if (err!=grOk) {
// Error occurred
printf("Graphics Error: %s",
grapherrormsg(err));
return 0;
}
// Mid positions at x and y-axis
midx = getmaxx() - 220;
midy = getmaxy() - 150;
// Manipulating radius of all
// the nine planets
long long int Planet[10000];
Planet[0] = 8;
for (i = 1; i < 9; i++) {
planet[i] = planet[i - 1] + 1;
}
// Offset position for the planets
// on their corresponding orbit
for (i = 0; i < 9; i++) {
pos[i] = i * 6;
}
// Orbits for all 9 planets
xrad[0] = 70, yrad[0] = 40;
for (i = 1; i < 9; i++) {
xrad[i] = xrad[i - 1] + 38;
yrad[i] = yrad[i - 1] + 20;
}
// Positions of planets on their
// corresponding orbits
for (i = 0; i < 9; i++) {
planetMotion(xrad[i], yrad[i],
midx, midy, x[i],
y[i]);
}
while (!kbhit()) {
// Drawing 9 orbits
setcolor(WHITE);
for (i = 0; i < 9; i++) {
setcolor(CYAN);
ellipse(midx, midy, 0, 360,
xrad[i], yrad[i]);
}
// Sun at the mid of solar system
outtextxy(midx, midy, " SUN");
setcolor(YELLOW);
setfillstyle(SOLID_FILL, YELLOW);
circle(midx, midy, 30);
floodfill(midx, midy, YELLOW);
// Mercury in first orbit
setcolor(CYAN);
setfillstyle(SOLID_FILL, CYAN);
outtextxy(x[0][pos[0]],
y[0][pos[0]],
"MERCURY");
pieslice(x[0][pos[0]],
y[0][pos[0]],
0, 360, planet[0]);
// Venus in second orbit
setcolor(GREEN);
setfillstyle(SOLID_FILL, GREEN);
outtextxy(x[1][pos[1]],
y[1][pos[1]],
" VENUS");
pieslice(x[1][pos[1]],
y[1][pos[1]],
0, 360, planet[1]);
// Earth in third orbit
setcolor(BLUE);
setfillstyle(SOLID_FILL, BLUE);
outtextxy(x[2][pos[2]],
y[2][pos[2]],
" EARTH");
pieslice(x[2][pos[2]],
y[2][pos[2]],
0, 360, planet[2]);
// Mars in fourth orbit
setcolor(RED);
setfillstyle(SOLID_FILL, RED);
outtextxy(x[3][pos[3]],
y[3][pos[3]],
" MARS");
pieslice(x[3][pos[3]],
y[3][pos[3]],
0, 360, planet[3]);
// Jupiter in fifth orbit
setcolor(BROWN);
setfillstyle(SOLID_FILL, BROWN);
outtextxy(x[4][pos[4]],
y[4][pos[4]],
" JUPITER");
pieslice(x[4][pos[4]],
y[4][pos[4]],
0, 360, planet[4]);
// Saturn in sixth orbit
setcolor(LIGHTGRAY);
setfillstyle(SOLID_FILL, LIGHTGRAY);
outtextxy(x[5][pos[5]],
y[5][pos[5]],
" SATURN");
pieslice(x[5][pos[5]],
y[5][pos[5]],
0, 360, planet[5]);
// Uranus in seventh orbit
setcolor(LIGHTGREEN);
setfillstyle(SOLID_FILL, LIGHTGREEN);
outtextxy (x [6] [pos [6]],
y [6] [pos [6]],
"URANUS");
pieslice (x [6] [pos [6]],
y [6] [pos [6]],
0, 360, planet [6]);
// Neptune in eighth orbit
setcolor (LIGHTBLUE);
setfillstyle (SOLID_FILL, LIGHTBLUE);
outtextxy (x [7] [pos [7]],
y [7] [pos [7]],
" NEPTUNE");
pieslice (x [7] [pos [7]],
y [7] [pos [7]],
0, 360, planet [7]);
// Pluto in ninth orbit
setcolor (LIGHTRED);
setfillstyle (SOLID_FILL, LIGHTRED);
outtextxy (x [8] [pos [8]],
y [8] [pos [8]],
" PLUTO");
pieslice (x [8] [pos [8]],
y [8] [pos [8]],
0, 360, planet [8]);
// Checking for one complete
// rotation
for (i = 0; i < 9; i++) {
if (pos[i] <= 0) {
pos[i] = 59;
}
else {
pos[i] = pos[i] - 1;
}
}
// Sleep for 100 milliseconds
delay (100);
// Clears graphic screen
cleardevice ();
}
// Deallocate memory allocated
// for graphic screen
closegraph();
return 0;
}