post-merge
* align meteor effect with upstream code * unified meteor & meteor smooth
This commit is contained in:
@@ -2531,18 +2531,22 @@ uint16_t mode_lake() {
|
||||
static const char _data_FX_MODE_LAKE[] PROGMEM = "Lake@!;Fx;!";
|
||||
|
||||
|
||||
// meteor effect
|
||||
// meteor effect & meteor smooth (merged by @dedehai)
|
||||
// send a meteor from begining to to the end of the strip with a trail that randomly decays.
|
||||
// adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain
|
||||
uint16_t mode_meteor() {
|
||||
static uint16_t mode_meteor_core(bool smooth) {
|
||||
if (SEGLEN == 1) return mode_oops();
|
||||
if (!SEGENV.allocateData(SEGLEN)) return mode_oops(); //allocation failed
|
||||
|
||||
const bool meteorSmooth = smooth || SEGMENT.check3;
|
||||
byte* trail = SEGENV.data;
|
||||
|
||||
const unsigned meteorSize= 1 + SEGLEN / 20; // 5%
|
||||
uint16_t counter = strip.now * ((SEGMENT.speed >> 2) +8);
|
||||
uint16_t in = counter * SEGLEN >> 16;
|
||||
const unsigned meteorSize = 1 + SEGLEN / 20; // 5%
|
||||
uint16_t meteorstart;
|
||||
if(meteorSmooth) meteorstart = map((SEGENV.step >> 6 & 0xFF), 0, 255, 0, SEGLEN -1);
|
||||
else {
|
||||
unsigned counter = strip.now * ((SEGMENT.speed >> 2) + 8);
|
||||
meteorstart = (counter * SEGLEN) >> 16;
|
||||
}
|
||||
|
||||
const int max = SEGMENT.palette==5 || !SEGMENT.check1 ? 240 : 255;
|
||||
// fade all leds to colors[1] in LEDs one step
|
||||
@@ -2573,58 +2577,37 @@ uint16_t mode_meteor() {
|
||||
}
|
||||
|
||||
// draw meteor
|
||||
for (unsigned j = 0; j < meteorSize; j++) {
|
||||
uint16_t index = in + j;
|
||||
if (index >= SEGLEN) {
|
||||
index -= SEGLEN;
|
||||
for (int j = 0; j < meteorSize; j++) {
|
||||
int index = (meteorstart + j) % SEGLEN;
|
||||
if(meteorSmooth) {
|
||||
trail[index] = max;
|
||||
uint32_t col = SEGMENT.check1 ? SEGMENT.color_from_palette(index, true, false, 0, trail[index]) : SEGMENT.color_from_palette(trail[index], false, true, 255);
|
||||
SEGMENT.setPixelColor(index, col);
|
||||
}
|
||||
trail[index] = max;
|
||||
uint32_t col = SEGMENT.check1 ? SEGMENT.color_from_palette(index, true, false, 0, trail[index]) : SEGMENT.color_from_palette(trail[index], false, true, 255);
|
||||
SEGMENT.setPixelColor(index, col);
|
||||
}
|
||||
|
||||
return FRAMETIME;
|
||||
}
|
||||
static const char _data_FX_MODE_METEOR[] PROGMEM = "Meteor@!,Trail,,,,Gradient;;!;1";
|
||||
|
||||
|
||||
// smooth meteor effect
|
||||
// send a meteor from begining to to the end of the strip with a trail that randomly decays.
|
||||
// adapted from https://www.tweaking4all.com/hardware/arduino/adruino-led-strip-effects/#LEDStripEffectMeteorRain
|
||||
uint16_t mode_meteor_smooth() {
|
||||
if (SEGLEN == 1) return mode_oops();
|
||||
if (!SEGENV.allocateData(SEGLEN)) return mode_oops(); //allocation failed
|
||||
|
||||
byte* trail = SEGENV.data;
|
||||
|
||||
const unsigned meteorSize= 1+ SEGLEN / 20; // 5%
|
||||
uint16_t in = map((SEGENV.step >> 6 & 0xFF), 0, 255, 0, SEGLEN -1);
|
||||
|
||||
const int max = SEGMENT.palette==5 || !SEGMENT.check1 ? 240 : 255;
|
||||
// fade all leds to colors[1] in LEDs one step
|
||||
for (int i = 0; i < SEGLEN; i++) {
|
||||
if (/*trail[i] != 0 &&*/ random8() <= 255 - SEGMENT.intensity) {
|
||||
int change = trail[i] + 4 - random8(24); //change each time between -20 and +4
|
||||
trail[i] = constrain(change, 0, max);
|
||||
uint32_t col = SEGMENT.check1 ? SEGMENT.color_from_palette(i, true, false, 0, trail[i]) : SEGMENT.color_from_palette(trail[i], false, true, 255);
|
||||
SEGMENT.setPixelColor(i, col);
|
||||
else{
|
||||
int idx = 255;
|
||||
int i = trail[index] = max;
|
||||
if (!SEGMENT.check1) {
|
||||
i = map(index,0,SEGLEN,0,max);
|
||||
idx = 0;
|
||||
}
|
||||
uint32_t col = SEGMENT.color_from_palette(i, false, false, idx, 255); // full brightness
|
||||
SEGMENT.setPixelColor(index, col);
|
||||
}
|
||||
}
|
||||
|
||||
// draw meteor
|
||||
for (unsigned j = 0; j < meteorSize; j++) {
|
||||
uint16_t index = in + j;
|
||||
if (index >= SEGLEN) {
|
||||
index -= SEGLEN;
|
||||
}
|
||||
trail[index] = max;
|
||||
uint32_t col = SEGMENT.check1 ? SEGMENT.color_from_palette(index, true, false, 0, trail[index]) : SEGMENT.color_from_palette(trail[index], false, true, 255);
|
||||
SEGMENT.setPixelColor(index, col);
|
||||
}
|
||||
|
||||
SEGENV.step += SEGMENT.speed +1;
|
||||
return FRAMETIME;
|
||||
}
|
||||
|
||||
uint16_t mode_meteor() {
|
||||
return mode_meteor_core(false);
|
||||
}
|
||||
static const char _data_FX_MODE_METEOR[] PROGMEM = "Meteor@!,Trail,,,,Gradient,,Smooth;;!;1";
|
||||
|
||||
uint16_t mode_meteor_smooth() {
|
||||
return mode_meteor_core(true);
|
||||
}
|
||||
static const char _data_FX_MODE_METEOR_SMOOTH[] PROGMEM = "Meteor Smooth@!,Trail,,,,Gradient;;!;1";
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user