首页 > 解决方案 > 如何在颤动中使用画布创建宠物爪标志

问题描述

我正在尝试使用颤振动态创建一个爪子宠物画布作为以下徽标:

宠物爪标志

当我尝试创建一个使用Paint()Canvas 作为以下代码时:

class PetLogo extends CustomPainter {
  @override
  void paint(Canvas canvas, Size size) {
    // TODO: implement paint
    Paint paint = Paint();
    paint
      ..color = Colors.white
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 3;

    Paint paint1 = Paint();
    paint1
      ..color = Colors.transparent
      ..style = PaintingStyle.fill
      ..strokeWidth = 0;

    var paint2 = Paint()
      ..color = Colors.white
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 3;
    //a circle
    canvas.drawCircle(Offset(0, 9), 18, paint2);

    var paint3 = Paint()
      ..color = Colors.white
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 3;
    //a circle
    canvas.drawCircle(Offset(50, 0), 22, paint3);

    var paint4 = Paint()
      ..color = Colors.white
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeWidth = 3;
    //a circle
    canvas.drawCircle(Offset(100, 10), 18, paint4);

    double width = size.width;
    double height = size.height;

    Path path = Path();
    path.moveTo(0.5 * width, height * 0.45);
    path.cubicTo(0.2 * width, height * 0.1, -0.50 * width, height * 0.6,
        0.5 * width, height);
    path.moveTo(0.5 * width, height * 0.45);
    path.cubicTo(0.8 * width, height * 0.1, 1.50 * width, height * 0.6,
        0.5 * width, height);

    canvas.drawPath(path, paint1);
    canvas.drawPath(path, paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}

因为最终输出如下图所示:

颤振器代码

那么有没有人可以帮我完成这幅画?

标签: flutterdart

解决方案


推荐阅读