-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
48 lines (39 loc) · 931 Bytes
/
main.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
#include <bits/stdc++.h>
#include <iomanip>
#include <string>
#include "math.h"
constexpr double GRAVITY = 9.8;
/**
* Prepares the terminal emulator for the simulation.
*/
void setup()
{
system("clear"); // clear the console
std::cout.setf(std::ios::unitbuf); // turn off stdout buffer
std::cout.sync_with_stdio(false);
std::cout << "\033[?25l"; // disable cursor blinking
std::cout << "\033[0;1H"; // move cursor to [0][1]
}
// usage:
// - '--help'
// - accleration rows
int main(int argc, char **argv)
{
if (strcmp(argv[1], "--help") == 0)
{
std::cout << "Usage: freefall <distance>" << std::endl;
return 0;
}
setup();
int d = std::stoi(argv[1]);
auto vt = computeTime(d,
computeVelocity(GRAVITY, d)
);
for (auto t = vt.rbegin(); t != vt.rend(); ++t) {
std::cout << "*";
usleep(*t * 1000000);
std::cout << "\b \b"; // erase rock
std::cout << "\033[B"; // move cursor down
}
return 0;
}