Lava constructor
Lava({
- required double width,
- required double widthTolerance,
- required bool growAndShrink,
- required double growthRate,
- required double growthRateTolerance,
- required double blurLevel,
- required List<
Color> colors, - required bool allSameColor,
- required bool fadeBetweenColors,
- required bool changeColorsTogether,
- required double speed,
- 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);
}
}
}