Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2D Effect Snow Fall #147

Merged
merged 7 commits into from
Oct 2, 2024
Merged

2D Effect Snow Fall #147

merged 7 commits into from
Oct 2, 2024

Conversation

Brandon502
Copy link

@Brandon502 Brandon502 commented Jul 17, 2024

Effect that simulates snow/sand falling and melting.

Uses getBitValue and setBitValue from Game of Life to reduce memory usage to 1 bit per led.

Sliders:

  • Effect Speed: 0 to 60 updates per second
  • Spawn Chance: 0% to ~39% chance
  • Despawn Chance: 0% to ~38% chance. 255 = 100% chance
  • Blur: Fade previous snow location
  • Sway Chance: 0% to 100% chance of swaying while free falling

Check boxes:

  • Use Palette: Uses palette instead of default snow colors
  • Overlay: Allows background effect to color the snow
  • Prevent Overflow: If snow reaches the top the bottom opens and empties current snow

I've optimized this as much as I can, easily hits 60fps on 32x32. Likely can still be improved.

Examples on a 32x32 split into 2 segments using different slider/option configs.

Screen.Recording.2024-07-13.192733.mp4
Screen.Recording.2024-07-13.192931.mp4
Screen.Recording.2024-07-13.194249.mp4

Naming and default values can be changed however you'd like. Started out as snow, but palette colors look really nice. Could likely be modified to have an audio reactive version as well.

@softhack007
Copy link
Collaborator

Hi @Brandon502, nice effect, thank you 😃

I'm a bit busy right now - just tested your effect quickly on 64x64 and it looks very good.
I can take a closer look at the code in the next weeks.

cheers

wled00/FX.cpp Outdated
// Despawn snow
bool overflow = SEGENV.aux0 && SEGMENT.check3;
int despawnChance = SEGMENT.custom1 == 255 ? 256 : map(SEGMENT.custom1, 0, 255, 0, 100); // 255 goes to 256, allows always despawn
int y = rows - 1;
Copy link
Collaborator

Choose a reason for hiding this comment

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

"y" causes a warning later (line 5423) about shadowing a local variable.
I'd suggest you name this one "lowY"

wled00/FX.cpp Outdated
if (SEGENV.aux0) --SEGENV.aux0; // Decrease overflow

// Precompute shuffled indices, helps randomize snow movement
int shuffledIndices[cols];
Copy link
Collaborator

Choose a reason for hiding this comment

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

this variable-sized array is allocated from the heap. You could change the type to uint16_t to reduce heap pressure a bit.

wled00/FX.h Outdated
@@ -349,8 +349,9 @@ bool strip_uses_global_leds(void); // WLEDMM implemented in FX_fcn.
// #define FX_MODE_PALETTE_AR 193 // WLED-SR audioreactive palette
#define FX_MODE_FIREWORKS_AR 194 // WLED-SR audioreactive fireworks
#define FX_MODE_GEQLASER 195 // WLED-MM GEQ Laser
#define FX_MODE_2DSNOWFALL 196 // WLED-MM Snowfall
Copy link
Collaborator

Choose a reason for hiding this comment

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

@troyhacks already claimed 196 for his new effect - next available one is 197

Copy link
Collaborator

@softhack007 softhack007 left a comment

Choose a reason for hiding this comment

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

just some minor comments from my side (see above).
Just see if you want to fix them, then increase the FX number.

Thanks 👍

@Brandon502
Copy link
Author

just some minor comments from my side (see above). Just see if you want to fix them, then increase the FX number.

Thanks 👍

Thank you for reviewing. Made all the recommended changes.

@softhack007 softhack007 merged commit e103a96 into MoonModules:mdev Oct 2, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants