debsahu / NeoAnimationFX

This uses NeoPixelBrightnessBus and borrows code from awesome animations developed at WS2812FX.
GNU General Public License v3.0
16 stars 4 forks source link

Meteor Rain color changing #2

Open Viktus04 opened 6 years ago

Viktus04 commented 6 years ago

Hello,

I am totally new to programming and I already talked to Tobias Blum because I'm using the Mc Lighting platform for my Wemos D1, he said that maybe you could help me. I want the Meteor Rain Effect to change the color after every cycle. I already tried to do it by myself but I'm not getting to the point where it works like this, I added the color_wheel the color is changing extremely fast and not after every cycle. but maybe I'm wrong with that. maybe you have a quick solution for me?

Thank you very much for your great work!

  uint16_t meteorRain(uint8_t meteorTrailDecay, boolean meteorRandomDecay) {  
    uint16_t meteorSize = SEGMENT_LENGTH * 0.20;

    SEGMENT_RUNTIME.aux_param = get_random_wheel_index(SEGMENT_RUNTIME.aux_param);
    RgbColor color = color_wheel(SEGMENT_RUNTIME.aux_param);

    if(SEGMENT_RUNTIME.counter_mode_step == 0){
      _strip.ClearTo(rgbcolor_black);
    }

    if( SEGMENT_RUNTIME.counter_mode_step <= SEGMENT_LENGTH*2 ) {
      // fade brightness all LEDs one step
      for(uint16_t i=0; i <= SEGMENT_LENGTH; i++) {
        if( (!meteorRandomDecay) || (random(10)>5) ) {
          fadeToBlackVal(i, meteorTrailDecay );        
        }
      }
      // draw meteor
  for(uint16_t i = 0; i <= meteorSize; i++) {
        if( ( (SEGMENT_RUNTIME.counter_mode_step)-i <= SEGMENT_LENGTH) && ((SEGMENT_RUNTIME.counter_mode_step)-i >= 0) ) {
          if(!SEGMENT.reverse){
            this->setPixelColor(SEGMENT_RUNTIME.counter_mode_step - i, color);
          } else {
            this->setPixelColor(SEGMENT_LENGTH - SEGMENT_RUNTIME.counter_mode_step + i, color);
          }
        } 
      }
    } 

    SEGMENT_RUNTIME.counter_mode_step = (SEGMENT_RUNTIME.counter_mode_step + 1) % SEGMENT_LENGTH;
    return
    (SEGMENT.speed / SEGMENT_LENGTH);
  }

  uint16_t mode_meteor_rain(void) {
    return meteorRain(64, true);
  }
toblum commented 6 years ago

Hi @Viktus04,

you mentioned the comet effect. That is a bit easier to read. The meteor effect is more complex to understand for me, without trying it out. Honestly I didn't look in detail how the effects work, so far. I think the goal is to find the position in code where the effect starts again. I couldn't try it out, but maybe after "_strip.ClearTo(rgbcolor_black);" could be the right position to reset the color.

Best regards Tobias

debsahu commented 6 years ago

@Viktus04 @toblum Sorry dont have my computer and setup to test it. @toblum is right, all you have to do is set a SEGMENT.colors[0] to some color you like after _strip.ClearTo(rgbcolor_black);