fire animation: decrease flashiness & increase saturation

This commit is contained in:
Thomas Kolb 2023-05-25 23:35:41 +02:00
parent 04fd4fc7c8
commit 3948210d2a

View file

@ -12,9 +12,11 @@ use rand::Rng;
const COOLDOWN_FACTOR : f32 = 0.99995; const COOLDOWN_FACTOR : f32 = 0.99995;
const MAX_ENERGY_PROPAGATION : f32 = 0.4; const MAX_ENERGY_PROPAGATION : f32 = 0.4;
const RM_ENERGY : f32 = 0.02; const RM_ENERGY_SUB : f32 = 0.011;
const EXPONENT : f32 = 0.97; const RM_ENERGY_MULT : f32 = 0.995;
const W_EXPONNET : f32 = 0.03; const EXPONENT : f32 = 1.50;
const W_EXPONENT : f32 = 2.20;
const W_SCALE : f32 = 0.3;
const OVERDRIVE : f32 = 0.3; const OVERDRIVE : f32 = 0.3;
// A single-color flame. // A single-color flame.
@ -55,8 +57,9 @@ impl Flame
// globally remove energy // globally remove energy
for led in 0..config::NUM_LEDS_PER_STRIP { for led in 0..config::NUM_LEDS_PER_STRIP {
if self.energy[strip][led] > RM_ENERGY { self.energy[strip][led] *= RM_ENERGY_MULT;
self.energy[strip][led] -= RM_ENERGY; if self.energy[strip][led] > RM_ENERGY_SUB {
self.energy[strip][led] -= RM_ENERGY_SUB;
} else { } else {
self.energy[strip][led] = 0.0; self.energy[strip][led] = 0.0;
} }
@ -154,7 +157,7 @@ impl Animation for Fire
self.r_flame.update((cur_energy.r / self.max_energy.r).powf(EXPONENT)); self.r_flame.update((cur_energy.r / self.max_energy.r).powf(EXPONENT));
self.g_flame.update((cur_energy.g / self.max_energy.g).powf(EXPONENT)); self.g_flame.update((cur_energy.g / self.max_energy.g).powf(EXPONENT));
self.b_flame.update((cur_energy.b / self.max_energy.b).powf(EXPONENT)); self.b_flame.update((cur_energy.b / self.max_energy.b).powf(EXPONENT));
self.w_flame.update((cur_energy.w / self.max_energy.w).powf(EXPONENT)); self.w_flame.update((cur_energy.w / self.max_energy.w).powf(W_EXPONENT));
//self.r_flame.print(); //self.r_flame.print();
@ -165,7 +168,7 @@ impl Animation for Fire
r: self.r_flame.get_energy(strip, led), r: self.r_flame.get_energy(strip, led),
g: self.g_flame.get_energy(strip, led), g: self.g_flame.get_energy(strip, led),
b: self.b_flame.get_energy(strip, led), b: self.b_flame.get_energy(strip, led),
w: self.w_flame.get_energy(strip, led) w: self.w_flame.get_energy(strip, led) * W_SCALE
}; };
self.colorlists[strip][led].limit(); self.colorlists[strip][led].limit();