drawStar method

Graphics drawStar(
  1. double x,
  2. double y,
  3. int points,
  4. double radius, [
  5. double? innerRadius,
  6. double rotation = 0,
])

Draws a star polygon with a given number of points and radius from the center point (x, y). An optional innerRadius can be specified to create a star shape. The star can also be rotated by rotation angle (defaults to 0).

Returns the current Graphics instance, allowing for method chaining.

Implementation

Graphics drawStar(
  double x,
  double y,
  int points,
  double radius, [
  double? innerRadius,
  double rotation = 0,
]) {
  innerRadius ??= radius / 2;
  final startAngle = (-1 * Math.PI1_2) + rotation;
  final len = points * 2;
  final delta = Math.PI_2 / len;
  final polys = <Offset>[];
  for (var i = 0; i < len; ++i) {
    final r = i.isOdd ? innerRadius : radius;
    final a = i * delta + startAngle;
    polys.add(Offset(
      x + (r * Math.cos(a)),
      y + (r * Math.sin(a)),
    ));
  }
  _path!.addPolygon(polys, true);
  return this;
}