generateRandomPos function

Vector2 generateRandomPos(
  1. double x,
  2. double y,
  3. double mag,
  4. double width,
  5. double height,
)

Implementation

Vector2 generateRandomPos(
    double x, double y, double mag, double width, double height) {
  final pos = Vector2(x, y);
  final vel = Vector2(randD(0, width), randD(0, height));
  vel.sub(pos);
  vel.normalize();
  vel.scale(mag);
  pos.add(vel);

  return pos;
}