Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 20 additions & 16 deletions wled00/FX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2379,13 +2379,15 @@ void mode_meteor() {
if (SEGLEN <= 1) FX_FALLBACK_STATIC;
if (!SEGENV.allocateData(SEGLEN)) FX_FALLBACK_STATIC; //allocation failed
const bool meteorSmooth = SEGMENT.check3;
const bool slow = SEGMENT.check2;
byte* trail = SEGENV.data;

const unsigned meteorSize = 1 + SEGLEN / 20; // 5%
const unsigned numMeteors = 1 + (SEGMENT.custom1 >> 5); // 1..8 meteors
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);
unsigned counter = strip.now * (slow ? (SEGMENT.speed >> 4) + 1 : (SEGMENT.speed >> 2) + 8);
meteorstart = (counter * SEGLEN) >> 16;
}

Expand Down Expand Up @@ -2417,29 +2419,31 @@ void mode_meteor() {
}
}

// draw meteor
for (unsigned j = 0; j < meteorSize; j++) {
unsigned index = (meteorstart + j) % SEGLEN;
if(meteorSmooth) {
// draw meteor(s), evenly spaced along the strip
for (unsigned m = 0; m < numMeteors; m++) {
unsigned start = (meteorstart + m * SEGLEN / numMeteors) % SEGLEN;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@coderabbitai i'm seeing a jump in the example shown by the PR author. Please check if the math is correct here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- Focused source ---'
ast-grep outline wled00/FX.cpp --match mode_meteor --view expanded
sed -n '2365,2460p' wled00/FX.cpp

printf '%s\n' '--- PR diff for Meteor ---'
git diff --unified=80 HEAD^ HEAD -- wled00/FX.cpp | sed -n '/void mode_meteor()/,/static const char _data_FX_MODE_METEOR/p'

printf '%s\n' '--- Spacing and wrap simulation ---'
python3 - <<'PY'
cases = [(10, 3), (17, 3), (17, 6), (30, 8), (60, 8), (144, 8)]
for length, count in cases:
    print(f"\nSEGLEN={length}, numMeteors={count}")
    previous = None
    for meteorstart in range(length):
        starts = [((meteorstart + m * length // count) % length) for m in range(count)]
        ordered = sorted(starts)
        gaps = [ordered[i + 1] - ordered[i] for i in range(count - 1)]
        gaps.append(length + ordered[0] - ordered[-1])
        if previous is not None:
            moved = sorted((starts[i] - previous[i]) % length for i in range(count))
            if moved != [1] * count:
                print(f"  discontinuity from {meteorstart - 1} to {meteorstart}: {previous} -> {starts}, movement={moved}")
                break
        previous = starts
    print(f"  starts at phase 0: {[m * length // count for m in range(count)]}")
    print(f"  circular gaps: {gaps}")
PY

Length of output: 9010


@softhack007, I checked the position math.

(meteorstart + m * SEGLEN / numMeteors) % SEGLEN does not create a frame-to-frame jump. Each meteor advances by the same amount as meteorstart. The modulo also wraps a meteor from the last pixel to pixel zero.

The code does produce unequal spacing when SEGLEN is not divisible by numMeteors. Integer division rounds each offset down.

For example, with SEGLEN == 60 and numMeteors == 8, the gaps are:

8, 7, 8, 7, 8, 7, 8, 7

Therefore, the pattern has fixed one-pixel spacing differences. This can look like a jump in a visual recording, especially on a short segment. Exact equal spacing is impossible on the integer pixel grid for this case.

I do not find a wraparound or arithmetic discontinuity in this line. The reported effect is likely the unavoidable rounding distribution.

You are interacting with an AI system.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jump may also be due to my failed attempt at trying to get a nice looping gif.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

for (unsigned j = 0; j < meteorSize; j++) {
unsigned index = (start + 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);
}
else{
int idx = 255;
int i = trail[index] = max;
if (!SEGMENT.check1) {
i = map(index,0,SEGLEN,0,max);
idx = 0;
} 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);
}
uint32_t col = SEGMENT.color_from_palette(i, false, false, idx, 255); // full brightness
SEGMENT.setPixelColor(index, col);
}
}

SEGENV.step += SEGMENT.speed +1;
SEGENV.step += (slow ? SEGMENT.speed >> 3 : SEGMENT.speed) + 1;
}
static const char _data_FX_MODE_METEOR[] PROGMEM = "Meteor@!,Trail,,,,Gradient,,Smooth;;!;1";
static const char _data_FX_MODE_METEOR[] PROGMEM = "Meteor@!,Trail,# of Meteors,,,Gradient,Slow,Smooth;;!;1;c1=0";


//Railway Crossing / Christmas Fairy lights
Expand Down
Loading