Skip to content

Commit 9ea2303

Browse files
committed
DNA effect optimization (phases)
* non-breaking - reproduces the old behavior at phases = 127 * minor math optimizations * phase boost for large values (good for small panels)
1 parent 2bfa3b7 commit 9ea2303

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

wled00/FX.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5119,12 +5119,13 @@ static const char _data_FX_MODE_2DCOLOREDBURSTS[] PROGMEM = "Colored Bursts@Spee
51195119
/////////////////////
51205120
// 2D DNA //
51215121
/////////////////////
5122-
uint16_t mode_2Ddna(void) { // dna originally by by ldirko at https://pastebin.com/pCkkkzcs. Updated by Preyy. WLED conversion by Andrew Tuline.
5122+
uint16_t mode_2Ddna(void) { // dna originally by by ldirko at https://pastebin.com/pCkkkzcs. Updated by Preyy. WLED conversion by Andrew Tuline. Phases added by @ewoudwijma
51235123
if (!strip.isMatrix) return mode_static(); // not a 2D set-up
51245124

51255125
const uint16_t cols = SEGMENT.virtualWidth();
51265126
const uint16_t rows = SEGMENT.virtualHeight();
5127-
uint8_t phases = SEGMENT.custom1;
5127+
unsigned phases = SEGMENT.custom1;
5128+
if (phases > 179) phases = 179 + 2.5f * (phases - 179); // boost for values > 179
51285129

51295130
if (SEGENV.call == 0) {
51305131
SEGMENT.setUpLeds();
@@ -5137,10 +5138,9 @@ uint16_t mode_2Ddna(void) { // dna originally by by ldirko at https://pa
51375138
int lastY1 = -1;
51385139
int lastY2 = -1;
51395140
for (int i = 0; i < cols; i++) {
5140-
// int posY1 = beatsin8_t(SEGMENT.speed/8, 0, rows-1, 0, i*4 );
5141-
///int posY2 = beatsin8_t(SEGMENT.speed/8, 0, rows-1, 0, i*4+128);
5142-
unsigned phase = cols * i / 8; // 256 is a complete phase; half a phase is dna is 128
5143-
phase = i * 4 * phases / cols; // cols ==0 cannot happen due to the for loop
5141+
// 256 is a complete phase; half a phase of dna is 128
5142+
// unsigned phase = i * 4 * phases / cols; // original formula; cols ==0 cannot happen due to the for loop
5143+
unsigned phase = i * 4 * phases / 128; // WLEDMM this reproduces the previous behaviour at phases=127
51445144
int posY1 = beatsin8_t(SEGMENT.speed/8, 0, rows-1, 0, phase );
51455145
int posY2 = beatsin8_t(SEGMENT.speed/8, 0, rows-1, 0, phase+128);
51465146

0 commit comments

Comments
 (0)