update method

  1. @override
void update(
  1. double deltaTime,
  2. Size size
)
override

Implementation

@override
void update(double deltaTime, Size size) {
  //will change currentBlur linear to random values within [blur-blurPulseRange,blur+blurPulseRange]
  double absBlurPulseRange = blurPulseRange.getAbsoluteValue(size);
  double absBlur = blur.getAbsoluteValue(size);

  //if newBlur is reached set a new "targetBlur"
  if ((_currentBlur - _newBlur).abs() <=
          (absBlurPulseRange * blurPulseSpeed).abs() ||
      _newBlur == 0) {
    //blur goes up
    if (_currentBlur <= absBlur) {
      _newBlur = absBlur + absBlurPulseRange * Random().nextDouble();
      blurPulseSpeed = blurPulseSpeed.abs();
      //blur goes down
    } else if (_currentBlur > absBlur) {
      _newBlur = absBlur - absBlurPulseRange * Random().nextDouble();
      blurPulseSpeed = -blurPulseSpeed.abs();
    }
  }
  _currentBlur += absBlurPulseRange * blurPulseSpeed;

  if (super.isToggled) {
    if (Random().nextDouble() <= flickerOn) {
      super.toggle();
    }
  } else {
    if (Random().nextDouble() <= flickerOff) {
      super.toggle();
    }
  }

  //safety if currentBlur gets out of range to prevent error thrown
  if (_currentBlur <= 0) {
    _currentBlur = 1;
  } else if (_currentBlur > (absBlurPulseRange + absBlur)) {
    _currentBlur = (absBlurPulseRange + absBlur);
  }
}