ParallaxRainPainter(- {required int numberOfDrops,
- required Size parentSize,
- required double dropFallSpeed,
- required int numberOfLayers,
- required bool trail,
- required double dropHeight,
- required double dropWidth,
- required List<Color> dropColors,
- required double trailStartFraction,
- required double distanceBetweenLayers,
- required ValueNotifier notifier}
)
Implementation
ParallaxRainPainter(
{required this.numberOfDrops,
required this.parentSize,
required this.dropFallSpeed,
required this.numberOfLayers,
required this.trail,
required this.dropHeight,
required this.dropWidth,
required this.dropColors,
required this.trailStartFraction,
required this.distanceBetweenLayers,
required ValueNotifier notifier})
: super(repaint: notifier) {
paintObject = Paint()
..color = dropColors[0]
..style = PaintingStyle.fill;
double effectiveLayer;
for (int i = 0; i < this.numberOfDrops; i++) {
double x = random.nextDouble() * parentSize.width;
double y = random.nextDouble() * parentSize.height;
// Keeping [widget.numberOfLayers] layers for the parallax effect, the base values are for the layer furthest behind
int layerNumber =
random.nextInt(numberOfLayers); // 0 is the layer furthest behind
effectiveLayer = layerNumber * distanceBetweenLayers;
dropSize = new Size(dropWidth, dropHeight);
dropList.add(
new Drop(
drop: Offset(x, y) &
Size(
dropSize.width + (dropSize.width * effectiveLayer),
dropSize.height + (dropSize.height * effectiveLayer),
),
dropSpeed:
this.dropFallSpeed + (this.dropFallSpeed * effectiveLayer),
dropLayer: layerNumber,
dropColor: dropColors[random.nextInt(dropColors.length)]),
);
}
}