1 #include <Display/Animations/AnimationFire.hpp> 2 #include <Engine/Graphics/Colors.hpp> 3 #include <Engine/Helpers/Utils.hpp> 5 static ColorPair red = Colors::pair(
"red",
"default");
6 static ColorPair redBold = Colors::pair(
"red",
"default",
true);
7 static ColorPair white;
8 static ColorPair yellow = Colors::pair(
"yellow",
"default");
9 static ColorPair yellowBold = Colors::pair(
"yellow",
"default",
true);
16 static int gray_scale_size = 12;
17 static char gray_scale[13] =
" .':-=+*#%@#";
19 AnimationFire::AnimationFire(Window* window):
23 AnimationFire::~AnimationFire()
25 SAFE_DELETE(particle);
27 void AnimationFire::load()
29 unsigned int width = window->getW();
30 unsigned int height = window->getH();
32 particle =
new Array2D<ParticleFire>(width, height);
35 coolingMap =
new Array2D<int>(width, height);
37 for (
unsigned int i = 0; i < width; i++)
38 for (
unsigned int j = 0; j < height; j++)
39 coolingMap->set(i, j, Utils::Random::between(INTENSITY_MIN,
40 INTENSITY_PERCENT(13)));
43 for (
int n = 0; n < 10; n++)
44 for (
unsigned int i = 1; i < width-1; i++)
45 for (
unsigned int j = 1; j < height-1; j++)
46 coolingMap->set(i, j, (coolingMap->at(i-1, j) +
47 coolingMap->at(i+1, j) +
48 coolingMap->at(i, j+1) +
49 coolingMap->at(i, j-1)) / 4);
53 void AnimationFire::update()
56 if (timer.delta_ms() < 100)
60 int cooling_ratio = Utils::Random::between(INTENSITY_PERCENT(3),
61 INTENSITY_PERCENT(12));
64 bool burst = Utils::Random::booleanWithChance(0.10);
65 bool dim = Utils::Random::booleanWithChance(0.12);
66 if (burst) cooling_ratio = INTENSITY_PERCENT(1);
67 if (dim) cooling_ratio = INTENSITY_PERCENT(30);
70 for (
unsigned int i = 0; i < (particle->width()); i++)
71 particle->set(i, particle->height() - 1,
ParticleFire(Utils::Random::between(INTENSITY_PERCENT(90), INTENSITY_MAX)));
74 for (
unsigned int i = 0; i < (particle->width()); i++)
76 if (Utils::Random::booleanWithChance(2.31))
78 int height = particle->height() - Utils::Random::between(3, 6);
80 particle->set(i, height,
ParticleFire(Utils::Random::between(INTENSITY_PERCENT(90), INTENSITY_MAX)));
85 for (
unsigned int i = 0; i < (particle->width()); i++)
87 for (
unsigned int j = 0; j < (particle->height()-1); j++)
90 particle->set(i, j,
ParticleFire(particle->at(i, j + 1).intensity - cooling_ratio));
93 particle->set(i, j,
ParticleFire(particle->at(i, j).intensity - coolingMap->at(i, j)));
99 void AnimationFire::draw()
101 for (
unsigned int i = 0; i < (particle->width()); i++)
103 for (
unsigned int j = 0; j < (particle->height()); j++)
107 int s = particle->at(i, j).intensity;
109 if (s > INTENSITY_PERCENT(90))
112 else if (s > INTENSITY_PERCENT(80))
115 else if (s > INTENSITY_PERCENT(70))
118 else if (s > INTENSITY_PERCENT(60))
121 else if (s > INTENSITY_PERCENT(50))
124 else if (s > INTENSITY_PERCENT(40))
127 else if (s > INTENSITY_PERCENT(30))
130 else if (s > INTENSITY_PERCENT(20))
137 if ((s > INTENSITY_MAX) || (s < INTENSITY_MIN))
141 c = gray_scale[(s - INTENSITY_MIN) * (gray_scale_size-1)/INTENSITY_MAX];
143 window->printChar(c, i, j, p);
A single particle inside the whole fire.