Skip to content

Commit 3c74abf

Browse files
authored
Update README.md
1 parent 2990b8e commit 3c74abf

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

usermods/user_fx/README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ if (!strip.isMatrix || !SEGMENT.is2D())
5151
return mode_static(); // not a 2D set-up
5252
```
5353
The next code block contains several constant variable definitions which essentially serve to extract the dimensions of the user's 2D matrix and allow WLED to interpret the matrix as a 1D coordinate system (WLED must do this for all 2D animations):
54-
```
54+
```cpp
5555
const int cols = SEG_W;
5656
const int rows = SEG_H;
5757
const auto XY = [&](int x, int y) { return x + y * cols; };
@@ -64,7 +64,7 @@ const auto XY = [&](int x, int y) { return x + y * cols; };
6464
* WLED internally treats the LED strip as a 1D array, so effects must translate 2D coordinates into 1D indices. This lambda helps with that.
6565
6666
The next lines of code further the setup process by defining variables that allow the effect's settings to be configurable using the UI sliders (or alternatively, through API calls):
67-
```
67+
```cpp
6868
const uint8_t refresh_hz = map(SEGMENT.speed, 0, 255, 20, 80);
6969
const unsigned refresh_ms = 1000 / refresh_hz;
7070
const int16_t diffusion = map(SEGMENT.custom1, 0, 255, 0, 100);
@@ -85,14 +85,14 @@ const uint8_t turbulence = SEGMENT.custom2;
8585

8686
Next we will look at some lines of code that handle memory allocation and effect initialization:
8787

88-
```
88+
```cpp
8989
unsigned dataSize = SEGMENT.length();
9090
```
9191
* This part calculates how much memory we need to represent per-pixel state.
9292
* `SEGMENT.length()` returns the total number of LEDs in the current segment (i.e., cols * rows in a matrix).
9393
* This fire effect models heat values per pixel (not just colors), so we need persistent storage — one uint8_t per pixel — for the entire effect.
9494

95-
```
95+
```cpp
9696
if (!SEGENV.allocateData(dataSize))
9797
return mode_static(); // allocation failed
9898
```
@@ -103,7 +103,7 @@ return mode_static(); // allocation failed
103103

104104

105105
The next lines of code clear the LEDs and initialize timing:
106-
```
106+
```cpp
107107
if (SEGENV.call == 0) {
108108
SEGMENT.fill(BLACK);
109109
SEGENV.step = 0;
@@ -115,7 +115,7 @@ if (SEGENV.call == 0) {
115115
* It also initializes `SEGENV.step`, a timing marker, to 0. This value is later used as a timestamp to control when the next animation frame should occur (based on elapsed time).
116116

117117
The next block of code is where the animation update logic starts to kick in:
118-
```
118+
```cpp
119119
if ((strip.now - SEGENV.step) >= refresh_ms) {
120120
uint8_t tmp_row[cols];
121121
SEGENV.step = strip.now;
@@ -134,7 +134,7 @@ if ((strip.now - SEGENV.step) >= refresh_ms) {
134134
* Note that this is declared on the stack each frame. Since the number of columns is typically small (e.g. ≤ 16), it's efficient.
135135
136136
Now we get to the spark generation portion, where new bursts of heat appear at the bottom of the matrix:
137-
```
137+
```cpp
138138
if (hw_random8() > turbulence) {
139139
// create new sparks at bottom row
140140
for (unsigned x = 0; x < cols; x++) {
@@ -161,7 +161,7 @@ if (hw_random8() > turbulence) {
161161
* This simulates a fresh burst of flame, which will diffuse and move upward over time in subsequent frames.
162162

163163
Next we reach the first part of the core of the fire simulation, which is diffusion (how heat spreads to neighboring pixels):
164-
```
164+
```cpp
165165
// diffuse
166166
for (unsigned y = 0; y < rows; y++) {
167167
for (unsigned x = 0; x < cols; x++) {
@@ -188,7 +188,7 @@ for (unsigned y = 0; y < rows; y++) {
188188
* This entire line of code stores the smoothed heat into the temporary row buffer.
189189
190190
After calculating tmp_row, we now handle rendering the pixels by updating the actual segment data and turning 'heat' into visible colors:
191-
```
191+
```cpp
192192
for (unsigned x = 0; x < cols; x++) {
193193
SEGMENT.data[XY(x, y)] = tmp_row[x];
194194
if (SEGMENT.check1) {
@@ -213,7 +213,7 @@ After calculating tmp_row, we now handle rendering the pixels by updating the ac
213213
* The final line of code fades that base color according to the heat value (acts as brightness multiplier).
214214

215215
The final piece of this custom effect returns the frame time:
216-
```
216+
```cpp
217217
}
218218
return FRAMETIME;
219219
}
@@ -229,7 +229,7 @@ return FRAMETIME;
229229
### The Metadata String
230230
At the end of every effect is an important line of code called the **metadata string**.
231231
It defines how the effect is to be interacted with in the UI:
232-
```
232+
```cpp
233233
static const char _data_FX_MODE_DIFFUSIONFIRE[] PROGMEM = "Diffusion Fire@!,Spark rate,Diffusion Speed,Turbulence,,Use palette;;Color;;2;pal=35";
234234
```
235235
This string is passed into `strip.addEffect()` and parsed by WLED to determine how your effect appears and behaves in the UI.
@@ -241,7 +241,7 @@ Let’s split this into logical sections (delimited by semicolons ;):
241241
### The UserFxUsermod Class
242242

243243
The `UserFxUsermod` class registers the `mode_diffusionfire` effect with WLED. This section starts right after the effect function and metadata string, and is responsible for making the effect usable in the WLED interface:
244-
```
244+
```cpp
245245
class UserFxUsermod : public Usermod {
246246
private:
247247
public:
@@ -278,7 +278,7 @@ class UserFxUsermod : public Usermod {
278278
* USERMOD_ID_USER_FX is defined in [const.h](https://github.com/wled/WLED/blob/main/wled00/const.h). WLED uses this for tracking, debugging, or referencing usermods internally.
279279
280280
The final part of this file handles instatiation and initialization:
281-
```
281+
```cpp
282282
static UserFxUsermod user_fx;
283283
REGISTER_USERMOD(user_fx);
284284
```

0 commit comments

Comments
 (0)