Drip to virtualStrip
This commit is contained in:
parent
38bd0d6bbb
commit
d56a79e016
126
wled00/FX.cpp
126
wled00/FX.cpp
@ -3375,91 +3375,83 @@ static const char _data_FX_MODE_EXPLODING_FIREWORKS[] PROGMEM = "Fireworks 1D@Gr
|
|||||||
*/
|
*/
|
||||||
uint16_t mode_drip(void)
|
uint16_t mode_drip(void)
|
||||||
{
|
{
|
||||||
const uint16_t cols = strip.isMatrix ? SEGMENT.virtualWidth() : 1;
|
|
||||||
const uint16_t rows = strip.isMatrix ? SEGMENT.virtualHeight() : SEGMENT.virtualLength();
|
|
||||||
|
|
||||||
//allocate segment data
|
//allocate segment data
|
||||||
uint8_t numDrops = 4;
|
uint8_t maxNumDrops = 4;
|
||||||
uint16_t dataSize = sizeof(spark) * numDrops;
|
uint16_t dataSize = sizeof(spark) * maxNumDrops;
|
||||||
if (!SEGENV.allocateData(dataSize * cols)) return mode_static(); //allocation failed
|
if (!SEGENV.allocateData(dataSize * SEGMENT.nrOfVStrips())) return mode_static(); //allocation failed
|
||||||
|
Spark* drops = reinterpret_cast<Spark*>(SEGENV.data);
|
||||||
|
|
||||||
SEGMENT.fill(SEGCOLOR(1));
|
SEGMENT.fill(SEGCOLOR(1));
|
||||||
|
|
||||||
Spark* drops = reinterpret_cast<Spark*>(SEGENV.data);
|
struct virtualStrip {
|
||||||
|
static void runStrip(uint16_t stripNr, Spark* drops) {
|
||||||
|
|
||||||
numDrops = 1 + (SEGMENT.intensity >> 6); // 255>>6 = 3
|
uint8_t numDrops = 1 + (SEGMENT.intensity >> 6); // 255>>6 = 3
|
||||||
|
|
||||||
float gravity = -0.0005 - (SEGMENT.speed/50000.0);
|
float gravity = -0.0005 - (SEGMENT.speed/50000.0);
|
||||||
gravity *= rows-1;
|
gravity *= (SEGLEN*1)-1;
|
||||||
int sourcedrop = 12;
|
int sourcedrop = 12;
|
||||||
|
|
||||||
for (int k=0; k < cols; k++) {
|
for (int j=0;j<numDrops;j++) {
|
||||||
for (size_t j=0; j < numDrops; j++) {
|
if (drops[j].colIndex == 0) { //init
|
||||||
uint16_t idx = k*numDrops + j;
|
drops[j].pos = (SEGLEN*1)-1; // start at end
|
||||||
|
drops[j].vel = 0; // speed
|
||||||
if (drops[idx].colIndex == 0) { //init
|
drops[j].col = sourcedrop; // brightness
|
||||||
drops[idx].pos = rows-1; // start at end
|
drops[j].colIndex = 1; // drop state (0 init, 1 forming, 2 falling, 5 bouncing)
|
||||||
drops[idx].vel = 0; // speed
|
|
||||||
drops[idx].col = sourcedrop; // brightness
|
|
||||||
drops[idx].colIndex = 1; // drop state (0 init, 1 forming, 2 falling, 5 bouncing)
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t col = color_blend(BLACK, SEGCOLOR(0), sourcedrop);
|
|
||||||
if (strip.isMatrix) SEGMENT.setPixelColorXY(k, 0, col);
|
|
||||||
else SEGMENT.setPixelColor(rows-1, col);// water source
|
|
||||||
|
|
||||||
if (drops[idx].colIndex == 1) {
|
|
||||||
if (drops[idx].col > 255) drops[idx].col = 255;
|
|
||||||
col = color_blend(BLACK,SEGCOLOR(0),drops[idx].col);
|
|
||||||
if (strip.isMatrix) SEGMENT.setPixelColorXY(k, rows - 1 - uint16_t(drops[idx].pos), col);
|
|
||||||
else SEGMENT.setPixelColor(uint16_t(drops[idx].pos), col);
|
|
||||||
|
|
||||||
drops[idx].col += map(SEGMENT.speed, 0, 255, 1, 6); // swelling
|
|
||||||
|
|
||||||
if (random8() < drops[idx].col/10) { // random drop
|
|
||||||
drops[idx].colIndex = 2; //fall
|
|
||||||
drops[idx].col = 255;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (drops[idx].colIndex > 1) { // falling
|
|
||||||
if (drops[idx].pos > 0) { // fall until end of segment
|
|
||||||
drops[idx].pos += drops[idx].vel;
|
|
||||||
if (drops[idx].pos < 0) drops[idx].pos = 0;
|
|
||||||
drops[idx].vel += gravity; // gravity is negative
|
|
||||||
|
|
||||||
for (int i = 1; i < 7 - drops[idx].colIndex; i++) { // some minor math so we don't expand bouncing droplets
|
SEGMENT.setPixelColor(stripNr, (SEGLEN*1)-1, color_blend(BLACK,SEGCOLOR(0), sourcedrop));// water source
|
||||||
uint16_t pos = constrain(uint16_t(drops[idx].pos) +i, 0, rows-1); //this is BAD, returns a pos >= SEGLEN occasionally
|
if (drops[j].colIndex==1) {
|
||||||
col = color_blend(BLACK, SEGCOLOR(0), drops[idx].col/i);
|
if (drops[j].col>255) drops[j].col=255;
|
||||||
if (strip.isMatrix) SEGMENT.setPixelColorXY(k, rows - 1 - pos, col);
|
SEGMENT.setPixelColor(stripNr, uint16_t(drops[j].pos), color_blend(BLACK,SEGCOLOR(0),drops[j].col));
|
||||||
else SEGMENT.setPixelColor(pos, col); //spread pixel with fade while falling
|
|
||||||
|
drops[j].col += map(SEGMENT.speed, 0, 255, 1, 6); // swelling
|
||||||
|
|
||||||
|
if (random8() < drops[j].col/10) { // random drop
|
||||||
|
drops[j].colIndex=2; //fall
|
||||||
|
drops[j].col=255;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (drops[j].colIndex > 1) { // falling
|
||||||
|
if (drops[j].pos > 0) { // fall until end of segment
|
||||||
|
drops[j].pos += drops[j].vel;
|
||||||
|
if (drops[j].pos < 0) drops[j].pos = 0;
|
||||||
|
drops[j].vel += gravity; // gravity is negative
|
||||||
|
|
||||||
if (drops[idx].colIndex > 2) { // during bounce, some water is on the floor
|
for (int i=1;i<7-drops[j].colIndex;i++) { // some minor math so we don't expand bouncing droplets
|
||||||
col = color_blend(SEGCOLOR(0), BLACK, drops[idx].col);
|
uint16_t pos = constrain(uint16_t(drops[j].pos) +i, 0, SEGLEN-1); //this is BAD, returns a pos >= SEGLEN occasionally
|
||||||
if (strip.isMatrix) SEGMENT.setPixelColorXY(k, rows - 1, col);
|
SEGMENT.setPixelColor(pos | int((stripNr+1)<<16), color_blend(BLACK,SEGCOLOR(0),drops[j].col/i)); //spread pixel with fade while falling
|
||||||
else SEGMENT.setPixelColor(0, col);
|
}
|
||||||
}
|
|
||||||
} else { // we hit bottom
|
|
||||||
if (drops[idx].colIndex > 2) { // already hit once, so back to forming
|
|
||||||
drops[idx].colIndex = 0;
|
|
||||||
drops[idx].col = sourcedrop;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
if (drops[idx].colIndex == 2) { // init bounce
|
if (drops[j].colIndex > 2) { // during bounce, some water is on the floor
|
||||||
drops[idx].vel = -drops[idx].vel/4;// reverse velocity with damping
|
SEGMENT.setPixelColor(0 | int((stripNr+1)<<16), color_blend(SEGCOLOR(0),BLACK,drops[j].col));
|
||||||
drops[idx].pos += drops[idx].vel;
|
}
|
||||||
}
|
} else { // we hit bottom
|
||||||
drops[idx].col = sourcedrop*2;
|
if (drops[j].colIndex > 2) { // already hit once, so back to forming
|
||||||
drops[idx].colIndex = 5; // bouncing
|
drops[j].colIndex = 0;
|
||||||
|
drops[j].col = sourcedrop;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (drops[j].colIndex==2) { // init bounce
|
||||||
|
drops[j].vel = -drops[j].vel/4;// reverse velocity with damping
|
||||||
|
drops[j].pos += drops[j].vel;
|
||||||
|
}
|
||||||
|
drops[j].col = sourcedrop*2;
|
||||||
|
drops[j].colIndex = 5; // bouncing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
|
for (int stripNr=0; stripNr<SEGMENT.nrOfVStrips(); stripNr++)
|
||||||
|
virtualStrip::runStrip(stripNr, &drops[stripNr*maxNumDrops]);
|
||||||
|
|
||||||
return FRAMETIME;
|
return FRAMETIME;
|
||||||
}
|
}
|
||||||
static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips;!,!;!;1d,2d";
|
static const char _data_FX_MODE_DRIP[] PROGMEM = "Drip@Gravity,# of drips;!,!;!;mp12=1,1d"; //bar
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user