ANTIPALSU Label template editor using flutter

arc_curves_painter.dart 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright (c) 2021 Razeware LLC
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a copy
  4. // of this software and associated documentation files (the "Software"), to deal
  5. // in the Software without restriction, including without limitation the rights
  6. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. // copies of the Software, and to permit persons to whom the Software is
  8. // furnished to do so, subject to the following conditions:
  9. //
  10. // The above copyright notice and this permission notice shall be included in
  11. // all copies or substantial portions of the Software.
  12. //
  13. // Notwithstanding the foregoing, you may not use, copy, modify, merge, publish,
  14. // distribute, sublicense, create a derivative work, and/or sell copies of the
  15. // Software in any work that is designed, intended, or marketed for pedagogical
  16. // or instructional purposes related to programming, coding, application
  17. // development, or information technology. Permission for such use, copying,
  18. // modification, merger, publication, distribution, sublicensing, creation of
  19. // derivative works, or sale is expressly withheld.
  20. //
  21. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  27. // THE SOFTWARE.
  28. import 'dart:math' as math;
  29. import 'package:flutter/material.dart';
  30. class ArcsCurvesPainter extends CustomPainter {
  31. final curvesPaint = Paint()
  32. ..strokeWidth = 5
  33. ..color = Colors.greenAccent[700]!
  34. ..style = PaintingStyle.stroke;
  35. @override
  36. void paint(Canvas canvas, Size size) {
  37. const arcCenter = Offset(200, 80);
  38. final arcRect = Rect.fromCircle(center: arcCenter, radius: 75);
  39. final startAngle = degreesToRadians(10);
  40. final sweepAngle = degreesToRadians(-90);
  41. canvas.drawArc(arcRect, startAngle, sweepAngle, false, curvesPaint);
  42. // Quadratic Bézier
  43. final qCurve1 = Path()
  44. ..moveTo(50, 150)
  45. ..relativeQuadraticBezierTo(100, -100, 300, 0);
  46. canvas.drawPath(qCurve1, curvesPaint..color = Colors.deepPurpleAccent);
  47. final qCurve2 = Path()
  48. ..moveTo(0, 150)
  49. ..relativeQuadraticBezierTo(150, 300, 300, 100);
  50. canvas.drawPath(qCurve2, curvesPaint..color = Colors.blue);
  51. // Cubic Bézier
  52. final cCurve1 = Path()
  53. ..moveTo(0, 450)
  54. ..relativeCubicTo(50, -100, 250, -100, 300, 0);
  55. canvas.drawPath(cCurve1, curvesPaint..color = Colors.black);
  56. final cCurve2 = Path()
  57. ..moveTo(380, 300)
  58. ..relativeCubicTo(0, 450, -300, 300, -150, 250);
  59. canvas.drawPath(cCurve2, curvesPaint..color = Colors.pink);
  60. }
  61. @override
  62. bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
  63. double degreesToRadians(double degrees) {
  64. return (degrees * math.pi) / 180;
  65. }
  66. }