-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCodeCloud.cpp
More file actions
119 lines (103 loc) · 3.74 KB
/
Copy pathCodeCloud.cpp
File metadata and controls
119 lines (103 loc) · 3.74 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
#include "pch.h"
#include "CodeCloud.h"
#include "../NetRain_Common/Consts.h"
namespace N_CodeRain
{
CodeCloud::CodeCloud(int raindrop_count)
{
this->raindrop_count = raindrop_count;
Raindrop** raindrops = new Raindrop* [raindrop_count + 1];
for (int i = 0; i < raindrop_count; i++)
{
*(raindrops + i) = generate_raindrop_rand();
}
raindrops[raindrop_count] = NULL;
this->raindrops = raindrops;
}
Raindrop* CodeCloud::generate_raindrop_rand()
{
int tail_length = rand() % 3;
int fall_seconds_mult = IGNORE_VALUE;
int** symbols = nullptr;
int* change_seconds_mult = nullptr;
float* opacity = nullptr;
generate_raindrop_params(tail_length, fall_seconds_mult, symbols, change_seconds_mult, opacity);
return new Raindrop(tail_length, fall_seconds_mult, symbols, change_seconds_mult, opacity);
}
void CodeCloud::generate_raindrop_params(int& tail_length, int& fall_seconds_mult, int** &symbols,
int* &change_seconds_mult, float* &opacity)
{
tail_length = (tail_length > IGNORE_VALUE) ? tail_length : RAINDROP_MIN_TAIL_SIZE + rand() % (RAINDROP_MAX_TAIL_SIZE - RAINDROP_MIN_TAIL_SIZE);
fall_seconds_mult = (fall_seconds_mult > IGNORE_VALUE) ? fall_seconds_mult : RAINDROP_MIN_FALL_SECONDS_MULT + rand() % (RAINDROP_MAX_FALL_SECONDS_MULT - RAINDROP_MIN_FALL_SECONDS_MULT);
int drop_count = DROPLET_LETTER_COUNT;
int** symbols_new = new int* [tail_length + 1];
int* change_seconds_mult_new = new int[tail_length + 1];
float* opacity_new = new float[tail_length + 1];
for (int j = 0; j < tail_length; j++)
{
int* symbols_tmp = new int[drop_count + 1];
for (int k = 0; k < drop_count; k++)
{
symbols_tmp[k] = DROPLET_RANDOM_LETTER_OFFSET_MIN + rand() % (DROPLET_RANDOM_LETTER_OFFSET_MAX - DROPLET_RANDOM_LETTER_OFFSET_MIN);
}
symbols_tmp[drop_count] = NULL;
symbols_new[j] = *&symbols_tmp;
change_seconds_mult_new[j] = j + 1;
opacity_new[j] = (drop_count / 100.0) * (tail_length - j);
}
symbols_new[tail_length] = NULL;
change_seconds_mult_new[tail_length] = NULL;
opacity_new[tail_length] = NULL;
if (symbols == nullptr)
{
symbols = symbols_new;
}
else
{
for (int i = 0; i < tail_length; i++)
{
delete[] symbols_new[i];
}
delete[] symbols_new;
}
if (change_seconds_mult == nullptr)
{
change_seconds_mult = change_seconds_mult_new;
}
else
{
delete[] change_seconds_mult_new;
}
if (opacity == nullptr)
{
opacity = opacity_new;
}
else
{
delete[] opacity_new;
}
}
Raindrop** CodeCloud::inspect_raindrops()
{
return this->raindrops;
}
void CodeCloud::reset_raindrop(int raindrop, int rows, int tail_length)
{
int fall_seconds_mult = IGNORE_VALUE;
int** symbols = nullptr;
int* change_seconds_mult = nullptr;
float* opacity = nullptr;
generate_raindrop_params(tail_length, fall_seconds_mult, symbols, change_seconds_mult, opacity);
this->raindrops[raindrop]->reset_raindrop(tail_length, fall_seconds_mult, change_seconds_mult, opacity, symbols, rows);
delete[] change_seconds_mult;
delete[] opacity;
delete[] symbols;
}
void CodeCloud::MakeItRain()
{
for (int i = 0; i < this->raindrop_count; i++)
{
raindrops[i]->fall();
}
}
}