-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathftwr.cpp
42 lines (34 loc) · 1018 Bytes
/
ftwr.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
/**
*** This is purely a toy.
*** I mean, you could use the same idea for displaying dialogues in a jRPG,
*** or sending packets at random intervals, or playing distracting sounds in a game.
**/
/** STL **/
#include <iostream>
#include <chrono>
#include <thread>
#include <random>
using namespace std;
void typeText(string text, int showFor = 0, bool clear = false)
{
static mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
using ms = chrono::milliseconds;
for(char c : text)
{
cout << c;
// sleep for random times to achieve the effect of typing
this_thread::sleep_for(ms(40 + (rnd() % 460)));
}
if(showFor > 0)
this_thread::sleep_for(ms(showFor));
if(clear)
cout <<'\r'<< string(text.size(), ' ') <<'\r';
}
int main()
{
typeText("Wake up, Neo...", 3000, true);
typeText("The Matrix has you...", 3000, true);
typeText("Follow the white rabbit.", 3000, true);
cout << "Knock, knock, Neo.\a";
return 0;
}