summaryrefslogtreecommitdiffstats
path: root/lib/screen/paints/arc_painter.dart
blob: 66e38d49f516504b8146d878010fa3878670b674 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// SPDX-License-Identifier: Apache-2.0

import 'dart:math';
import 'package:flutter/material.dart';

class LeftPainter extends CustomPainter {
  LeftPainter(
      {required this.radi,
      required this.currentValue,
      required this.bottomPadding,
      required this.color});

  late final double radi;
  late final double currentValue;
  late final double bottomPadding;
  late final Color color;

  Offset getLeftPoints(Size size, double radius, double value) {
    final double diam = 2 * radius;
    final double arcHalfAngle = asin(size.height / diam); //thetha
    final double currentAngle = (arcHalfAngle * value) / 50; //alpha
    return Offset(
        (radi * cos(arcHalfAngle)) +
            (size.width) -
            (radi * cos(arcHalfAngle - currentAngle)),
        (radi * sin(arcHalfAngle)) + (radi * sin(arcHalfAngle - currentAngle)));
  }

  @override
  void paint(Canvas canvas, Size size) {
    Offset startPoint = getLeftPoints(size, radi, bottomPadding);

    final paint = Paint()
      ..color = const Color.fromARGB(255, 49, 48, 48)
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeWidth = radi / 15;
    final paint2 = Paint()
      ..color = color
      ..strokeCap = StrokeCap.round
      ..style = PaintingStyle.stroke
      ..strokeWidth = radi / 15;

    final path = Path()
      ..moveTo(startPoint.dx, startPoint.dy)
      ..arcToPoint(Offset(size.width, 0), radius: Radius.circular(radi));
    canvas.drawPath(path, paint);
    final path2 = Path()
      ..moveTo(startPoint.dx, startPoint.dy)
      ..arcToPoint(
          getLeftPoints(size, radi,
              bottomPadding + ((1 - (bottomPadding / 100)) * currentValue)),
          radius: Radius.circular(radi));
    canvas.drawPath(path, paint);
    canvas.drawPath(path2, paint2);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}

class RightPainter extends CustomPainter {
  RightPainter(
      {required this.radi,
      required this.currentValue,
      required this.bottomPadding,
      required this.color});
  final double radi;
  final double currentValue;
  late final double bottomPadding;
  late final Color color;

  Offset getRightPoints(Size size, double radius, double value) {
    final double diam = 2 * radius;
    final double arcHalfAngle = asin(size.height / diam); //thetha
    final double currentAngle = (arcHalfAngle * value) / 50; //alpha
    return Offset(
        (radi * cos(arcHalfAngle - currentAngle)) - (radi * cos(arcHalfAngle)),
        (radi * sin(arcHalfAngle)) + (radi * sin(arcHalfAngle - currentAngle)));
  }

  @override
  void paint(Canvas canvas, Size size) {
    Offset startPoint = getRightPoints(size, radi, bottomPadding);
    final paint = Paint()
      ..color = const Color.fromARGB(255, 49, 48, 48)
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeWidth = radi / 15;

    final paint2 = Paint()
      ..color = color
      ..style = PaintingStyle.stroke
      ..strokeCap = StrokeCap.round
      ..strokeWidth = radi / 15;
    final path = Path()
      ..moveTo(startPoint.dx, startPoint.dy)
      ..arcToPoint(
        const Offset(0, 0),
        radius: Radius.circular(radi),
        clockwise: false,
      );
    final path2 = Path()
      ..moveTo(startPoint.dx, startPoint.dy)
      ..arcToPoint(
          getRightPoints(size, radi,
              bottomPadding + ((1 - (bottomPadding / 100)) * currentValue)),
          radius: Radius.circular(radi),
          clockwise: false);
    canvas.drawPath(path, paint);
    canvas.drawPath(path2, paint2);
  }

  @override
  bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
}