如何在Java和Kotlin中像弯曲的贝塞尔曲线一样绘制弯曲的路径

问题描述 投票:0回答:1

如何在Android中使用Java或Kotlin(如bezier方法)在Flutter中创建自定义形状?看这些图片,告诉我是否可以用Java创建这种形状?我搜索了更多次,但我无法理解是否有可能这样做以及使用女巫类。

<

android canvas flutter path curve
1个回答
0
投票
使用CustomPainter并使用path.quadraticBezierTo您可以参考此文档https://medium.com/@felixblaschke/fancy-background-animations-in-flutter-4163d50f5c37github https://github.com/felixblaschke/simple_animations_example_app

https://github.com/felixblaschke/simple_animations_example_app/blob/master/lib/examples/fancy_background.dart中的代码段

class CurvePainter extends CustomPainter { final double value; CurvePainter(this.value); @override void paint(Canvas canvas, Size size) { final white = Paint()..color = Colors.white.withAlpha(60); final path = Path(); final y1 = sin(value); final y2 = sin(value + pi / 2); final y3 = sin(value + pi); final startPointY = size.height * (0.5 + 0.4 * y1); final controlPointY = size.height * (0.5 + 0.4 * y2); final endPointY = size.height * (0.5 + 0.4 * y3); path.moveTo(size.width * 0, startPointY); path.quadraticBezierTo( size.width * 0.5, controlPointY, size.width, endPointY); path.lineTo(size.width, size.height); path.lineTo(0, size.height); path.close(); canvas.drawPath(path, white); } @override bool shouldRepaint(CustomPainter oldDelegate) { return true; } }

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.