-
Notifications
You must be signed in to change notification settings - Fork 0
/
stars.cpp
58 lines (49 loc) · 1.05 KB
/
stars.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
// Animating Stars in the CLI environemnt.
//
#include <iostream>
#include <iomanip>
#include <chrono>
#include <thread>
#include <cstdlib>
const int X_SIZE = 10;
const int Y_SIZE = 5;
int main()
{
char **arr = NULL;
char **ptr = NULL; // Adding a temporary place for traversing.
arr = new char*[X_SIZE];
for(int x = 0; x < X_SIZE; x++)
{
arr[x] = new char[Y_SIZE];
}
// Assign a temporary arr to the pointer ptr.
ptr = arr;
for(int x = 0; x < X_SIZE; ++x)
{
for(int y = 0; y < Y_SIZE; ++y)
{
if(((x + y) % 2) == 0)
{
*(*(ptr + x) + y) = '*';
}
else
{
*(*(ptr + x) + y) = '.';
}
}
}
while(true) {
for(int x = 0; x < rand() % X_SIZE; ++x)
{
std::chrono::milliseconds duration( 50 );
for(int y = 0; y < rand() % Y_SIZE; ++y)
{
std::this_thread::sleep_for(duration);
std::cout << std::right << std::setw(rand() % X_SIZE*10)
<< *(*(ptr + x) + y) << " ";
}
std::cout << std::endl;
}
}
return 0;
}