Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Sharing a Meteor Ra...
 
Share:
Notifications
Clear all

Sharing a Meteor Rain effects sketch

2 Posts
2 Users
1 Likes
354 Views
 Kip
(@kip)
Active Member
Joined: 2 years ago
Posts: 11
Topic starter  

I was inspired by the generous act of @lakerice sharing the sketch that he created and I thought I'd share this Meteor Rain master effects sketch that I have collected. Of course @Hans get the credit for sharing most of the sketches on this list! I've simply put the effects that he's shared plus some others that I have after playing around with the original code. The descriptions of the effects are in the sketch and the colors and other individual effects can be adjusted as needed. Enjoy! 

PS - @Hans, maybe you should create a place on your site kind of like the "Take a penny, leave a penny" concept. "Take a sketch, leave a sketch"! 🤔 

#include "FastLED.h"
#define NUM_LEDS 300
CRGB leds[NUM_LEDS];
#define PIN 9

void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}

void loop() {
//(R,G,B, After the color, we can set the meteor size – the number of LEDs that represent the meteor, not counting the tail of the meteor. 
  //The 5th parameter sets how fast the meteor tail decays/ disappears. A larger number makes the tail short and/or disappear faster. 
  //Theoretically a value of 64 should reduce the brightness by 25% for each time the meteor gets drawn.
  //Since meteors are not perfect, I’ve added the 6th parameter to mimic some sorts of difference in debris by making the decay a little random.
  //If this value is set to “true” then some randomness is added to the rail. If you set the value to “false” then the tail will be very smooth.
  //Finally there is the last parameter, which basically indicates how much the drawing speed has to be delayed. 
  //A value of zero (0) means maximum speed. Any value above zero indicates how many milliseconds (1000 milliseconds in a second) the drawing will be delayed.)



 // meteorRain - Color (red, green, blue), meteor size, trail decay, random trail decay (true/false), speed delay
    meteorRain(210, 0, 50, 4, 64, true, 4);
    meteorRainReverse(250, 70, 0, 3, 85, true, 2);
    meteorRainInsideOut(0, 80, 200, 2, 50, false, 5);
    meteorRainOutsideIn(250, 80, 50, 10, 65, true, 4);
    meteorRainCB(CRGB(10,30,10), CRGB(0,11,226),5 ,50 ,true, 0);
    meteorRainReverseCB(CRGB(10,10,30), CRGB(235,50,0),3 ,30 ,false, 0);
    meteorRainTransition(80,0xff,0xff,10, 64, true, 5);
}
//Starts at lowest number LED and goes to highest
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS; i++) {
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
      }
    }
   
    FastLED.show();
    delay(SpeedDelay);
  }
  
  }

//Starts at highest number LED and goes to lowest
void meteorRainReverse(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {  
  setAll(0,0,0);
 
  for(int i = 0; i < NUM_LEDS; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
      
    }
   
    // draw meteor
    for(int j = 0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(NUM_LEDS-i-j, red, green, blue);
      }
    }
   
    FastLED.show();
    delay(SpeedDelay);
  } 
}

//Starts at ends and goes to middle
void meteorRainOutsideIn(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)  {  
  setAll(0,0,0);
 
  for(int i = 0; i < (NUM_LEDS)/2; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      } 
    }
    // draw meteor
    for(int j=0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
        setPixel(NUM_LEDS-i-j, red, green, blue); //draw in reverse
      }
    }
   
  FastLED.show();
    delay(SpeedDelay);
  }
}

//Starts mid strip and goes to ends
void meteorRainInsideOut(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)  {  
  setAll(0,0,0);
 
  for(int i = 150; i < NUM_LEDS; i++) {
   
   
    // fade brightness all LEDs one step
    for(int j=0; j<NUM_LEDS; j++) {
      if( (!meteorRandomDecay) || (random(10)>5) ) {
        fadeToBlack(j, meteorTrailDecay );        
      }
      
    }
   
    // draw meteor
    for(int j =0; j < meteorSize; j++) {
      if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
        setPixel(i-j, red, green, blue);
        setPixel(NUM_LEDS-i-j, red, green, blue);
      }
    }
   
  FastLED.show();
    delay(SpeedDelay);
  }
}

//Meteor Rain with a Colored Background
void meteorRainCB(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
{
// set background color
fill_solid( leds, NUM_LEDS, ColorBackground );

for(int i = 0; i < NUM_LEDS; i++)
{
// fade color to background color for all LEDs
for(int j=0; j < NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10) > 5) ) {
leds[j] = fadeTowardColor(leds[j], ColorBackground, meteorTrailDecay );
}
}

// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j < NUM_LEDS) && (i-j >= 0) ) {
leds[i-j]= ColorMeteor;
}
}

FastLED.show();
delay(SpeedDelay);
}
}

// Reversed Meteor Rain with a Colored Background
void meteorRainReverseCB(CRGB ColorBackground, CRGB ColorMeteor, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay)
{
// set background color
fill_solid( leds, NUM_LEDS, ColorBackground );

for(int i = 0; i < NUM_LEDS; i++)
{
// fade color to background color for all LEDs
for(int j=0; j < NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10) > 5) ) {
leds[j] = fadeTowardColor(leds[j], ColorBackground, meteorTrailDecay );
}
}

// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j < NUM_LEDS) && (i-j >= 0) ) {
leds[NUM_LEDS-i-j]= ColorMeteor;
}
}

FastLED.show();
delay(SpeedDelay);
}
}

// Functions from Kriegsman example
CRGB fadeTowardColor( CRGB& cur, const CRGB& target, uint8_t amount)
{
nblendU8TowardU8( cur.red, target.red, amount);
nblendU8TowardU8( cur.green, target.green, amount);
nblendU8TowardU8( cur.blue, target.blue, amount);
return cur;
}

// function used by "fadeTowardColor"
void nblendU8TowardU8( uint8_t& cur, const uint8_t target, uint8_t amount)
{
if( cur == target) return;

if( cur < target ) {
uint8_t delta = target - cur;
delta = scale8_video( delta, amount);
cur += delta;
} else {
uint8_t delta = cur - target;
delta = scale8_video( delta, amount);
cur -= delta;
}
}

//meteorRainTransition
void meteorRainTransition(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) { 
setAll(0,0,0);

for(int i = 0; i < NUM_LEDS; i++) {

// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay ); 
}
}

// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}

FastLED.show();
delay(SpeedDelay);
}
}

void fadeToBlack(int ledNo, byte fadeValue) {
  // FastLED
   leds[ledNo].fadeToBlackBy( fadeValue ); 
}


void setPixel(int Pixel, byte red, byte green, byte blue) {
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
}

void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue);
  }
 FastLED.show();
}

ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 9 years ago
Posts: 2236
 

Hi Kip!

Thank you so much for sharing, it is always cool and appreciated to see the work of others 👍 

Take a sketch and leave a sketch - interesting idea! I like it.
I am however afraid that most will not leave a sketch.
If it is any indication of how things work: the LED Effects sketches have been downloaded more than 30,000 times - not even mentioning the folks that used copy and paste. From that maybe a handful of folks posted a comment and even less their sketches ...
But that's OK ... it is what it is and my purpose here is to share my experience(s) and hopefully help when I can ... 😉 
(still have to find time to look at your question from a month ago - OMG I cannot believe how fast time is going)


Kip reacted
ReplyQuote
Share: