Merge 'main' to 0_15
This commit is contained in:
commit
2e28df3e8a
@ -5169,7 +5169,7 @@ static const char _data_FX_MODE_2DLISSAJOUS[] PROGMEM = "Lissajous@X frequency,F
|
||||
///////////////////////
|
||||
// 2D Matrix //
|
||||
///////////////////////
|
||||
uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams. Adapted by Andrew Tuline & improved by merkisoft and ewowi.
|
||||
uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams. Adapted by Andrew Tuline & improved by merkisoft and ewowi, and softhack007.
|
||||
if (!strip.isMatrix || !SEGMENT.is2D()) return mode_static(); // not a 2D set-up
|
||||
|
||||
const uint16_t cols = SEGMENT.virtualWidth();
|
||||
@ -5177,6 +5177,8 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams.
|
||||
|
||||
if (SEGENV.call == 0) {
|
||||
SEGMENT.fill(BLACK);
|
||||
SEGENV.aux0 = SEGENV.aux1 = UINT16_MAX;
|
||||
SEGENV.step = 0;
|
||||
}
|
||||
|
||||
uint8_t fade = map(SEGMENT.custom1, 0, 255, 50, 250); // equals trail size
|
||||
@ -5194,32 +5196,43 @@ uint16_t mode_2Dmatrix(void) { // Matrix2D. By Jeremy Williams.
|
||||
|
||||
if (strip.now - SEGENV.step >= speed) {
|
||||
SEGENV.step = strip.now;
|
||||
// find out what color value is returned by gPC for a "falling code" example pixel
|
||||
// the color values returned may differ from the previously set values, due to
|
||||
// - auto brightness limiter (dimming)
|
||||
// - lossy color buffer (when not using global buffer)
|
||||
// - color balance correction
|
||||
// - segment opacity
|
||||
CRGB oldSpawnColor = spawnColor;
|
||||
if ((SEGENV.aux0 < cols) && (SEGENV.aux1 < rows)) { // we have a hint from last run
|
||||
oldSpawnColor = SEGMENT.getPixelColorXY(SEGENV.aux0, SEGENV.aux1); // find color of previous spawns
|
||||
SEGENV.aux1 ++; // our sample pixel will be one row down the next time
|
||||
}
|
||||
if ((oldSpawnColor == CRGB::Black) || (oldSpawnColor == trailColor)) oldSpawnColor = spawnColor; // reject "black", as it would mean that ALL pixels create trails
|
||||
|
||||
// move pixels one row down. Falling codes keep color and add trail pixels; all others pixels are faded
|
||||
for (int row=rows-1; row>=0; row--) {
|
||||
for (int col=0; col<cols; col++) {
|
||||
CRGB pix = SEGMENT.getPixelColorXY(col, row);
|
||||
if (pix == spawnColor) {
|
||||
if (pix == oldSpawnColor) { // this comparison may still fail due to overlays changing pixels, or due to gaps (2d-gaps.json)
|
||||
SEGMENT.setPixelColorXY(col, row, trailColor); // create trail
|
||||
if (row < rows-1) SEGMENT.setPixelColorXY(col, row+1, spawnColor);
|
||||
} else {
|
||||
// fade other pixels
|
||||
SEGMENT.setPixelColorXY(col, row, pix.nscale8(fade));
|
||||
if (pix != CRGB::Black) SEGMENT.setPixelColorXY(col, row, pix.nscale8(fade)); // optimization: don't fade black pixels
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// check for empty screen to ensure code spawn
|
||||
bool emptyScreen = true;
|
||||
for (int x=0; x<cols; x++) for (int y=0; y<rows; y++) {
|
||||
if (SEGMENT.getPixelColorXY(x,y)) {
|
||||
emptyScreen = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
bool emptyScreen = (SEGENV.aux1 >= rows); // empty screen means that the last falling code has moved out of screen area
|
||||
|
||||
// spawn new falling code
|
||||
if (random8() < SEGMENT.intensity || emptyScreen) {
|
||||
if (random8() <= SEGMENT.intensity || emptyScreen) {
|
||||
uint8_t spawnX = random8(cols);
|
||||
SEGMENT.setPixelColorXY(spawnX, 0, spawnColor);
|
||||
// update hint for next run
|
||||
SEGENV.aux0 = spawnX;
|
||||
SEGENV.aux1 = 0;
|
||||
}
|
||||
} // if millis
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user