From 05c0febd04e2b38435e0c2e8ced7aba601c349ae Mon Sep 17 00:00:00 2001 From: BaptisteHudyma Date: Tue, 12 Mar 2024 12:01:25 +0100 Subject: [PATCH] fix the 2d drift animation --- wled00/FX.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wled00/FX.cpp b/wled00/FX.cpp index 1f626bc9a2..7ceb83e264 100644 --- a/wled00/FX.cpp +++ b/wled00/FX.cpp @@ -5011,14 +5011,17 @@ uint16_t mode_2DDrift() { // By: Stepko https://editor.soulmateli const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t rows = SEGMENT.virtualHeight(); + const uint16_t colsCenter = (cols>>1) + (cols%2); + const uint16_t rowsCenter = (rows>>1) + (rows%2); + SEGMENT.fadeToBlackBy(128); const uint16_t maxDim = MAX(cols, rows)/2; unsigned long t = strip.now / (32 - (SEGMENT.speed>>3)); unsigned long t_20 = t/20; // softhack007: pre-calculating this gives about 10% speedup for (float i = 1; i < maxDim; i += 0.25) { float angle = radians(t * (maxDim - i)); - uint16_t myX = (cols>>1) + (uint16_t)(sin_t(angle) * i) + (cols%2); - uint16_t myY = (rows>>1) + (uint16_t)(cos_t(angle) * i) + (rows%2); + uint16_t myX = colsCenter + (sin_t(angle) * i); + uint16_t myY = rowsCenter + (cos_t(angle) * i); SEGMENT.setPixelColorXY(myX, myY, ColorFromPalette(SEGPALETTE, (i * 20) + t_20, 255, LINEARBLEND)); } SEGMENT.blur(SEGMENT.intensity>>3);