MCPcopy Create free account
hub / github.com/WayfireWM/wayfire / init_particle_with_node

Method init_particle_with_node

plugins/animate/fire/fire.cpp:49–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47 }
48
49 static void init_particle_with_node(Particle& p,
50 wf::geometry_t bounding_box, double progress)
51 {
52 p.life = 1;
53 p.fade = random(0.1, 0.6);
54
55 wf::color_t color_setting = fire_color;
56
57 float r;
58 float g;
59 float b;
60
61 if (!random_fire_color)
62 {
63 // The calculation here makes the variation lower at darker values
64 float randomize_amount_r = (color_setting.r * 0.857) / 2;
65 float randomize_amount_g = (color_setting.g * 0.857) / 2;
66 float randomize_amount_b = (color_setting.b * 0.857) / 2;
67
68 r = random(color_setting.r - randomize_amount_r,
69 std::min(color_setting.r + randomize_amount_r,
70 1.0));
71 g = random(color_setting.g - randomize_amount_g,
72 std::min(color_setting.g + randomize_amount_g,
73 1.0));
74 b = random(color_setting.b - randomize_amount_b,
75 std::min(color_setting.b + randomize_amount_b,
76 1.0));
77 } else
78 {
79 r = random(0, 1);
80 g = random(0, 1);
81 b = random(0, 1);
82
83 r = 2 * pow(r, 16);
84 g = 2 * pow(g, 16);
85 b = 2 * pow(b, 16);
86 }
87
88 p.color = {r, g, b, 1};
89
90 const double cur_pos = bounding_box.height * progress;
91 p.pos = {random(0, bounding_box.width), random(cur_pos - 10, cur_pos + 10)};
92 p.start_pos = p.pos;
93 p.speed = {random(-10, 10), random(-25, 5)};
94 p.g = {-1, -3};
95
96 double size = fire_particle_size;
97 p.base_radius = p.radius = random(size * 0.8, size * 1.2);
98 }
99
100 std::string stringify() const override
101 {

Callers

nothing calls this directly

Calls 1

randomFunction · 0.85

Tested by

no test coverage detected