drawPolygonFaces method

Graphics drawPolygonFaces(
  1. double x,
  2. double y,
  3. double radius,
  4. int sides, [
  5. double rotation = 0,
])

Draws a polygon with faces of equal size from the center point (x, y) to the circumference with a specified number of sides. The radius of the polygon can also be specified, along with an optional rotation angle.

The method returns this, which allows for method chaining.

Implementation

Graphics drawPolygonFaces(
  double x,
  double y,
  double radius,
  int sides, [
  double rotation = 0,
]) {
  final points = List<Offset>.filled(sides, Offset.zero);
  final rel = 2 * Math.PI / sides;
  for (var i = 1; i <= sides; ++i) {
    points[i - 1] = Offset(
      x + radius * Math.cos(i * rel + rotation),
      y + radius * Math.sin(i * rel + rotation),
    );
  }
  _path!.addPolygon(points, true);
  return this;
}