Popcorn to virtualStrip
This commit is contained in:
parent
e29be737f7
commit
9e23d52193
@ -2943,27 +2943,26 @@ typedef struct Spark {
|
|||||||
uint8_t colIndex;
|
uint8_t colIndex;
|
||||||
} spark;
|
} spark;
|
||||||
|
|
||||||
|
#define maxNumPopcorn 21 // max 21 on 16 segment ESP8266
|
||||||
/*
|
/*
|
||||||
* POPCORN
|
* POPCORN
|
||||||
* modified from https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/Popcorn.h
|
* modified from https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/Popcorn.h
|
||||||
*/
|
*/
|
||||||
uint16_t mode_popcorn(void) {
|
uint16_t mode_popcorn(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
|
||||||
uint16_t maxNumPopcorn = 21; // max 21 on 16 segment ESP8266
|
|
||||||
uint16_t dataSize = sizeof(spark) * maxNumPopcorn;
|
uint16_t dataSize = sizeof(spark) * maxNumPopcorn;
|
||||||
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
|
if (!SEGENV.allocateData(dataSize * SEGMENT.nrOfVStrips())) return mode_static(); //allocation failed
|
||||||
|
|
||||||
Spark* popcorn = reinterpret_cast<Spark*>(SEGENV.data);
|
Spark* popcorn = reinterpret_cast<Spark*>(SEGENV.data);
|
||||||
|
|
||||||
float gravity = -0.0001 - (SEGMENT.speed/200000.0); // m/s/s
|
|
||||||
gravity *= rows; //SEGLEN
|
|
||||||
|
|
||||||
bool hasCol2 = SEGCOLOR(2);
|
bool hasCol2 = SEGCOLOR(2);
|
||||||
SEGMENT.fill(hasCol2 ? BLACK : SEGCOLOR(1));
|
SEGMENT.fill(hasCol2 ? BLACK : SEGCOLOR(1));
|
||||||
|
|
||||||
|
struct virtualStrip {
|
||||||
|
static void runStrip(uint16_t stripNr, Spark* popcorn) {
|
||||||
|
float gravity = -0.0001 - (SEGMENT.speed/200000.0); // m/s/s
|
||||||
|
gravity *= SEGLEN;
|
||||||
|
|
||||||
uint8_t numPopcorn = SEGMENT.intensity*maxNumPopcorn/255;
|
uint8_t numPopcorn = SEGMENT.intensity*maxNumPopcorn/255;
|
||||||
if (numPopcorn == 0) numPopcorn = 1;
|
if (numPopcorn == 0) numPopcorn = 1;
|
||||||
|
|
||||||
@ -2974,18 +2973,17 @@ uint16_t mode_popcorn(void) {
|
|||||||
} else { // if kernel is inactive, randomly pop it
|
} else { // if kernel is inactive, randomly pop it
|
||||||
if (random8() < 2) { // POP!!!
|
if (random8() < 2) { // POP!!!
|
||||||
popcorn[i].pos = 0.01f;
|
popcorn[i].pos = 0.01f;
|
||||||
popcorn[i].posX = random16(cols);
|
|
||||||
|
|
||||||
uint16_t peakHeight = 128 + random8(128); //0-255
|
uint16_t peakHeight = 128 + random8(128); //0-255
|
||||||
peakHeight = (peakHeight * (rows -1)) >> 8;
|
peakHeight = (peakHeight * (SEGLEN -1)) >> 8;
|
||||||
popcorn[i].vel = sqrt(-2.0 * gravity * peakHeight);
|
popcorn[i].vel = sqrt(-2.0 * gravity * peakHeight);
|
||||||
popcorn[i].velX = 0;
|
|
||||||
|
|
||||||
if (SEGMENT.palette) {
|
if (SEGMENT.palette)
|
||||||
|
{
|
||||||
popcorn[i].colIndex = random8();
|
popcorn[i].colIndex = random8();
|
||||||
} else {
|
} else {
|
||||||
byte col = random8(0, NUM_COLORS);
|
byte col = random8(0, NUM_COLORS);
|
||||||
if (!hasCol2 || !SEGCOLOR(col)) col = 0;
|
if (!SEGCOLOR(2) || !SEGCOLOR(col)) col = 0;
|
||||||
popcorn[i].colIndex = col;
|
popcorn[i].colIndex = col;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2993,18 +2991,19 @@ uint16_t mode_popcorn(void) {
|
|||||||
if (popcorn[i].pos >= 0.0f) { // draw now active popcorn (either active before or just popped)
|
if (popcorn[i].pos >= 0.0f) { // draw now active popcorn (either active before or just popped)
|
||||||
uint32_t col = SEGMENT.color_wheel(popcorn[i].colIndex);
|
uint32_t col = SEGMENT.color_wheel(popcorn[i].colIndex);
|
||||||
if (!SEGMENT.palette && popcorn[i].colIndex < NUM_COLORS) col = SEGCOLOR(popcorn[i].colIndex);
|
if (!SEGMENT.palette && popcorn[i].colIndex < NUM_COLORS) col = SEGCOLOR(popcorn[i].colIndex);
|
||||||
|
|
||||||
uint16_t ledIndex = popcorn[i].pos;
|
uint16_t ledIndex = popcorn[i].pos;
|
||||||
if (ledIndex < rows) {
|
if (ledIndex < SEGLEN) SEGMENT.setPixelColor(ledIndex | int((stripNr+1)<<16), col);
|
||||||
if (strip.isMatrix) SEGMENT.setPixelColorXY(uint16_t(popcorn[i].posX), rows - 1 - ledIndex, col);
|
|
||||||
else SEGMENT.setPixelColor(ledIndex, col);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int stripNr=0; stripNr<SEGMENT.nrOfVStrips(); stripNr++)
|
||||||
|
virtualStrip::runStrip(stripNr, &popcorn[stripNr * maxNumPopcorn]);
|
||||||
|
|
||||||
return FRAMETIME;
|
return FRAMETIME;
|
||||||
}
|
}
|
||||||
static const char _data_FX_MODE_POPCORN[] PROGMEM = "Popcorn@!,!;!,!,!;!;1d,2d";
|
static const char _data_FX_MODE_POPCORN[] PROGMEM = "Popcorn@!,!;!,!,!;!;mp12=1,1d"; //bar
|
||||||
|
|
||||||
|
|
||||||
//values close to 100 produce 5Hz flicker, which looks very candle-y
|
//values close to 100 produce 5Hz flicker, which looks very candle-y
|
||||||
|
Loading…
Reference in New Issue
Block a user