initLine method

  1. @protected
void initLine(
  1. Line line
)

Initializes a line for this behaviour.

Implementation

@protected
void initLine(Line line) {
  line.speed = random.nextDouble() * 400 + 200;

  final bool axisHorizontal =
      (direction == LineDirection.Ltr || direction == LineDirection.Rtl);
  final bool normalDirection =
      (direction == LineDirection.Ltr || direction == LineDirection.Ttb);
  final double sizeCrossAxis = axisHorizontal ? size!.height : size!.width;
  final double sizeMainAxis = axisHorizontal ? size!.width : size!.height;
  final double spawnCrossAxis = random.nextInt(100) * (sizeCrossAxis / 100);
  double spawnMainAxis = 0.0;

  if (line.position == null) {
    spawnMainAxis = random.nextDouble() * sizeMainAxis;
  } else {
    spawnMainAxis = normalDirection
        ? (-line.speed / 2.0)
        : (sizeMainAxis + line.speed / 2.0);
  }

  line.position = axisHorizontal
      ? Offset(spawnMainAxis, spawnCrossAxis)
      : Offset(spawnCrossAxis, spawnMainAxis);
  line.thickness = random.nextInt(2) + 2;
  line.color = HSVColor.fromAHSV(
    random.nextDouble() * 0.3 + 0.2,
    random.nextInt(45) * 8.0,
    random.nextDouble() * 0.6 + 0.3,
    random.nextDouble() * 0.6 + 0.3,
  ).toColor();
}