Lava constructor

Lava({
  1. required double width,
  2. required double widthTolerance,
  3. required bool growAndShrink,
  4. required double growthRate,
  5. required double growthRateTolerance,
  6. required double blurLevel,
  7. required List<Color> colors,
  8. required bool allSameColor,
  9. required bool fadeBetweenColors,
  10. required bool changeColorsTogether,
  11. required double speed,
  12. required double speedTolerance,
})

Creates a new Lava object.

Implementation

Lava({
  required this.width,
  required this.widthTolerance,
  required this.growAndShrink,
  required this.growthRate,
  required this.growthRateTolerance,
  required this.blurLevel,
  required this.colors,
  required this.allSameColor,
  required this.fadeBetweenColors,
  required this.changeColorsTogether,
  required this.speed,
  required this.speedTolerance,
})  : assert(width > 0.0),
      assert(width - widthTolerance > 0.0),
      assert(growthRate >= 0.0),
      assert(growthRate - growthRateTolerance >= 0.0),
      assert(blurLevel >= 0.0),
      assert(colors.isNotEmpty, true),
      assert(speed >= 0),
      assert(speed - speedTolerance >= 0),
      _originalWidth = width,
      color =
          allSameColor ? colors[0] : colors[randInt(0, colors.length - 1)],
      _colorIndex = 0,
      _isGrowing = randInt(0, 9) % 2 == 0,
      position = initPosition,
      direction = LavaDirection.values[randInt(
        0,
        LavaDirection.values.length - 1,
      )],
      _previousAnimationValue = 10.0,
      _previousStep = 10,
      _fadePhase = allSameColor
          ? 0.0
          : changeColorsTogether
              ? 0.0
              : randDouble(0.0, 1.0) {
  // Randomly set the size of the circle.
  width += randDouble(-widthTolerance, widthTolerance);

  // Randomly set the speed of the circle.
  speed += randDouble(-speedTolerance, speedTolerance);

  // Randomly set the growth rate of the circle.
  growthRate += randDouble(-growthRateTolerance, growthRateTolerance);

  // Set the next color.
  if (colors.length == 1) {
    __nextColorIndex = 0;
  } else {
    if (allSameColor) {
      __nextColorIndex = (_colorIndex + 1) % colors.length;
    } else {
      __nextColorIndex = randInt(0, colors.length - 1);
    }
  }
}