myBall constructor

myBall({
  1. Key? key,
  2. required double xPoint,
  3. required double yPoint,
  4. required double xVelocity,
  5. required double yVelocity,
  6. required double ballRadius,
  7. required double ballMass,
  8. required double angularVelocity,
  9. List<Path> ballPath = const [],
  10. List<Paint> ballPaint = const [],
})

Implementation

myBall(
    {Key? key,
      required this.xPoint,
      required this.yPoint,
      required this.xVelocity,
      required this.yVelocity,
      required this.ballRadius,
      required this.ballMass,
      required this.angularVelocity,
      this.ballPath = const [],
      this.ballPaint = const [],
    }) {
  before_xPos = xPos;
  before_yPos = yPos;
  super.xPos = xPoint;
  super.yPos = yPoint;
  super.xVel = xVelocity;
  super.yVel = yVelocity;
  super.mass = ballMass;
  super.rMass = 1 / ballMass;
  ballRad = ballRadius;

  if(ballPath.length == 0){
    Path draw1 = Path();
    Path draw2 = Path();
    for (double i = 0; i < ballRad - 1; i++) {
      draw1.arcTo(
          Rect.fromCircle(
            radius: i,
            center: Offset(
              0,
              0,
            ),
          ),
          0 ,
          (1.9 * pi),
          true);

      draw2.arcTo(
          Rect.fromCircle(
            radius: i,
            center: Offset(
              0,
              0,
            ),
          ),
          1.9 * pi ,
          0.1 * pi,
          true);
    }


    draws.add(draw1);
    draws.add(draw2);

    backup_draws.add(draw1);
    backup_draws.add(draw2);
  }
  else{
    draws=ballPath;
    backup_draws=ballPath.toList();
  }


  if(ballPaint.length == 0) {
    Paint paint1 = Paint()
      ..color = Color(0xffcce0ff)
      ..style = PaintingStyle.stroke
      ..strokeWidth = 2;

    Paint paint2 = Paint()
      ..color = Color(0xffb0cfff)
      ..style = PaintingStyle.stroke
      ..strokeWidth = 2;

    paints.add(paint1);
    paints.add(paint2);
  }
  else{
    paints=ballPaint;
  }

  angularVel = angularVelocity;
  momentI = 0.5 * mass * ballRad * ballRad;


}