mirror of
https://github.com/wled/WLED.git
synced 2025-07-20 17:26:32 +00:00
cleanup and added Density slider
- moved local variables into function - made coordinates an array - amplitude can now be changed by user (default setting is a slight increase to original which cannot be avoided without complicated logic or default slider setting)
This commit is contained in:
parent
d92e60ee5f
commit
8e7d6d5dad
@ -7469,16 +7469,18 @@ static const char _data_FX_MODE_2DDISTORTIONWAVES[] PROGMEM = "Distortion Waves@
|
|||||||
//@Stepko
|
//@Stepko
|
||||||
//Idea from https://www.youtube.com/watch?v=DiHBgITrZck&ab_channel=StefanPetrick
|
//Idea from https://www.youtube.com/watch?v=DiHBgITrZck&ab_channel=StefanPetrick
|
||||||
// adapted for WLED by @blazoncek, optimization by @dedehai
|
// adapted for WLED by @blazoncek, optimization by @dedehai
|
||||||
void soapProcessPixels(bool isRow, uint8_t* noise3d, int amplitude, int shift, CRGB* ledsbuff) { //1153477-1152873
|
void soapProcessPixels(bool isRow, uint8_t* noise3d) {
|
||||||
const int cols = SEG_W;
|
const int cols = SEG_W;
|
||||||
const int rows = SEG_H;
|
const int rows = SEG_H;
|
||||||
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
|
const auto XY = [&](int x, int y) { return (x%cols) + (y%rows) * cols; };
|
||||||
int rowcol, colrow;
|
CRGB ledsbuff[MAX(cols,rows)];
|
||||||
rowcol = isRow ? rows : cols;
|
const int rowcol = isRow ? rows : cols;
|
||||||
colrow = isRow ? cols : rows;
|
const int colrow = isRow ? cols : rows;
|
||||||
|
int amplitude = isRow ? (cols-8) >> 3 : (rows-8) >> 3;
|
||||||
|
amplitude = 2 * max(1, amplitude * (1 + SEGMENT.custom1) >> 6);
|
||||||
|
|
||||||
for (int i = 0; i < rowcol; i++) {
|
for (int i = 0; i < rowcol; i++) {
|
||||||
int amount = ((int)noise3d[isRow ? i * cols : i] - 128) * 2 * amplitude + 256 * shift;
|
int amount = ((int)noise3d[isRow ? i * cols : i] - 128) * amplitude;
|
||||||
int delta = abs(amount) >> 8;
|
int delta = abs(amount) >> 8;
|
||||||
int fraction = abs(amount) & 255;
|
int fraction = abs(amount) & 255;
|
||||||
for (int j = 0; j < colrow; j++) {
|
for (int j = 0; j < colrow; j++) {
|
||||||
@ -7515,31 +7517,25 @@ uint16_t mode_2Dsoap() {
|
|||||||
const size_t dataSize = SEGMENT.width() * SEGMENT.height() * sizeof(uint8_t); // prevent reallocation if mirrored or grouped
|
const size_t dataSize = SEGMENT.width() * SEGMENT.height() * sizeof(uint8_t); // prevent reallocation if mirrored or grouped
|
||||||
if (!SEGENV.allocateData(dataSize + sizeof(uint32_t)*3)) return mode_static(); //allocation failed
|
if (!SEGENV.allocateData(dataSize + sizeof(uint32_t)*3)) return mode_static(); //allocation failed
|
||||||
|
|
||||||
uint8_t *noise3d = reinterpret_cast<uint8_t*>(SEGENV.data);
|
uint8_t *noise3d = reinterpret_cast<uint8_t*>(SEGENV.data);
|
||||||
uint32_t *noise32_x = reinterpret_cast<uint32_t*>(SEGENV.data + dataSize);
|
uint32_t *noisecoord = reinterpret_cast<uint32_t*>(SEGENV.data + dataSize); // x, y, z coordinates
|
||||||
uint32_t *noise32_y = reinterpret_cast<uint32_t*>(SEGENV.data + dataSize + sizeof(uint32_t));
|
|
||||||
uint32_t *noise32_z = reinterpret_cast<uint32_t*>(SEGENV.data + dataSize + sizeof(uint32_t)*2);
|
|
||||||
const uint32_t scale32_x = 160000U/cols;
|
const uint32_t scale32_x = 160000U/cols;
|
||||||
const uint32_t scale32_y = 160000U/rows;
|
const uint32_t scale32_y = 160000U/rows;
|
||||||
const uint32_t mov = MIN(cols,rows)*(SEGMENT.speed+2)/2;
|
const uint32_t mov = MIN(cols,rows)*(SEGMENT.speed+2)/2;
|
||||||
const uint8_t smoothness = MIN(250,SEGMENT.intensity); // limit as >250 produces very little changes
|
const uint8_t smoothness = MIN(250,SEGMENT.intensity); // limit as >250 produces very little changes
|
||||||
|
|
||||||
// init
|
for (int i = 0; i < 3; i++) {
|
||||||
if (SEGENV.call == 0) {
|
if (SEGENV.call == 0)
|
||||||
*noise32_x = hw_random();
|
noisecoord[i] = hw_random(); // init
|
||||||
*noise32_y = hw_random();
|
else
|
||||||
*noise32_z = hw_random();
|
noisecoord[i] += mov;
|
||||||
} else {
|
|
||||||
*noise32_x += mov;
|
|
||||||
*noise32_y += mov;
|
|
||||||
*noise32_z += mov;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < cols; i++) {
|
for (int i = 0; i < cols; i++) {
|
||||||
int32_t ioffset = scale32_x * (i - cols / 2);
|
int32_t ioffset = scale32_x * (i - cols / 2);
|
||||||
for (int j = 0; j < rows; j++) {
|
for (int j = 0; j < rows; j++) {
|
||||||
int32_t joffset = scale32_y * (j - rows / 2);
|
int32_t joffset = scale32_y * (j - rows / 2);
|
||||||
uint8_t data = inoise16(*noise32_x + ioffset, *noise32_y + joffset, *noise32_z) >> 8;
|
uint8_t data = inoise16(noisecoord[0] + ioffset, noisecoord[1] + joffset, noisecoord[2]) >> 8;
|
||||||
noise3d[XY(i,j)] = scale8(noise3d[XY(i,j)], smoothness) + scale8(data, 255 - smoothness);
|
noise3d[XY(i,j)] = scale8(noise3d[XY(i,j)], smoothness) + scale8(data, 255 - smoothness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -7554,21 +7550,12 @@ uint16_t mode_2Dsoap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int zD;
|
soapProcessPixels(true, noise3d); // rows
|
||||||
int zF;
|
soapProcessPixels(false, noise3d); // cols
|
||||||
int amplitude;
|
|
||||||
int shiftX = 0; //(SEGMENT.custom1 - 128) / 4;
|
|
||||||
int shiftY = 0; //(SEGMENT.custom2 - 128) / 4;
|
|
||||||
CRGB ledsbuff[MAX(cols,rows)];
|
|
||||||
|
|
||||||
amplitude = (cols >= 16) ? (cols-8)/8 : 1;
|
|
||||||
soapProcessPixels(true, noise3d, amplitude, shiftX, ledsbuff); // rows
|
|
||||||
amplitude = (rows >= 16) ? (rows-8)/8 : 1;
|
|
||||||
soapProcessPixels(false, noise3d, amplitude, shiftY, ledsbuff); // cols
|
|
||||||
|
|
||||||
return FRAMETIME;
|
return FRAMETIME;
|
||||||
}
|
}
|
||||||
static const char _data_FX_MODE_2DSOAP[] PROGMEM = "Soap@!,Smoothness;;!;2;pal=11";
|
static const char _data_FX_MODE_2DSOAP[] PROGMEM = "Soap@!,Smoothness,Density;;!;2;pal=11";
|
||||||
|
|
||||||
|
|
||||||
//Idea from https://www.youtube.com/watch?v=HsA-6KIbgto&ab_channel=GreatScott%21
|
//Idea from https://www.youtube.com/watch?v=HsA-6KIbgto&ab_channel=GreatScott%21
|
||||||
|
Loading…
x
Reference in New Issue
Block a user