paintFiveStart static method

void paintFiveStart(
  1. Canvas canvas,
  2. Offset center,
  3. double radius, {
  4. Color color = Colors.red,
  5. double rotateAngle = 0,
})

绘制五角星
center 中心点
radius 外接圆半径
color 文本颜色
rotateAngle 旋转角度

Implementation

static void paintFiveStart(
  Canvas canvas,
  Offset center,
  double radius, {
  Color color = Colors.red,
  double rotateAngle = 0,
}) {
  Offset p1 = Offset(0, -radius);
  Offset p2 = Offset(radius * sin(pi * 0.4), -radius * cos(pi * 0.4));
  Offset p3 = Offset(radius * sin(pi * 0.2), radius * cos(pi * 0.2));
  Offset p4 = Offset(-radius * sin(pi * 0.2), radius * cos(pi * 0.2));
  Offset p5 = Offset(-radius * sin(pi * 0.4), -radius * cos(pi * 0.4));
  Path path = Path();
  path.moveTo(p1.dx, p1.dy);
  path.lineTo(p3.dx, p3.dy);
  path.lineTo(p5.dx, p5.dy);
  path.lineTo(p2.dx, p2.dy);
  path.lineTo(p4.dx, p4.dy);
  path.lineTo(p1.dx, p1.dy);

  canvas.save();
  canvas.translate(center.dx, center.dy);
  canvas.rotate(-rotateAngle);
  // 绘制五角星
  canvas.drawPath(
      path,
      Paint()
        ..color = color
        ..style = PaintingStyle.fill);
  // 恢复画布到上一个save状态
  canvas.restore();
}