1 #include <Display/Animations/AnimationWater.hpp> 2 #include <Engine/Graphics/Colors.hpp> 3 #include <Engine/Helpers/Utils.hpp> 5 static ColorPair white;
6 static ColorPair blue = Colors::pair(
"blue",
"default" );
7 static ColorPair blueBold = Colors::pair(
"blue",
"default",
true);
8 static ColorPair cyan = Colors::pair(
"cyan",
"default" );
9 static ColorPair cyanBold = Colors::pair(
"cyan",
"default",
true);
11 static int gray_scale_size = 11;
12 static char gray_scale[12] =
"#@%#*+=-:'.";
14 AnimationWater::AnimationWater(Window* window):
19 AnimationWater::~AnimationWater()
24 void AnimationWater::load()
26 unsigned int width = window->getW();
27 unsigned int height = window->getH();
29 buffer1 =
new Array2D<int>(width, height);
30 buffer2 =
new Array2D<int>(width, height);
32 for (
unsigned int i = 0; i < width; i++)
34 for (
unsigned int j = 0; j < height; j++)
36 buffer1->set(i, j, Utils::Random::between(HEIGHT_MIN,
38 buffer2->set(i, j, Utils::Random::between(HEIGHT_MIN,
45 void AnimationWater::update()
48 if (timer.delta_ms() < 300)
52 Array2D<int>* tmp = buffer1;
57 if (Utils::Random::booleanWithChance(0.31))
58 buffer2->set(Utils::Random::between(0, buffer2->width()-1),
59 Utils::Random::between(0, buffer2->height()-1), HEIGHT_PERCENT(90));
62 for (
unsigned int i = 1; i < (buffer1->width() - 1); i++)
64 for (
unsigned int j = 1; j < (buffer1->height() - 1); j++)
68 buffer2->set(i, j, ((buffer1->at(i-1, j) +
71 buffer1->at(i, j-1)) >> 1) - buffer2->at(i, j));
79 void AnimationWater::draw()
81 for (
unsigned int i = 0; i < (buffer2->width()); i++)
83 for (
unsigned int j = 0; j < (buffer2->height()); j++)
87 int s = buffer2->at(i, j);
89 if (s > HEIGHT_PERCENT(80))
92 else if (s > HEIGHT_PERCENT(60))
95 else if (s > HEIGHT_PERCENT(40))
98 else if (s > HEIGHT_PERCENT(20))
104 if ((s > HEIGHT_MAX) || (s < HEIGHT_MIN))
108 c = gray_scale[(s - HEIGHT_MIN) * (gray_scale_size-1)/HEIGHT_MAX];
110 window->printChar(c, i, j, p);