-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogress_circle.py
85 lines (75 loc) · 2.2 KB
/
progress_circle.py
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
from ursina import *
class Circle(Mesh):
def __init__(self, resolution=100, radius=1, completion_percentage=1.0, mode='line', **kwargs):
origin = Entity()
point = Entity(parent=origin)
point.y = radius
self.vertices = []
for i in range(resolution):
if i > resolution * completion_percentage: break
origin.rotation_z -= 360 / resolution
self.vertices.append(point.world_position)
destroy(origin)
super().__init__(vertices=self.vertices, mode=mode, **kwargs)
class ProgressCircle(Entity):
def __init__(self, position, *args, outer_color=color.lime, inner_color=color.dark_gray, thickness=30,
completion_percentage=1.0, radius=.1, text="", **kwargs):
super().__init__(
parent=camera.ui,
position=position,
*args,
**kwargs
)
self.inner_color = inner_color
self.outer_color = outer_color
self.thickness = thickness
self.radius = radius
self.completion_percentage = completion_percentage
self.silent_inner_circle = Entity(
parent=self,
model=Circle(
thickness=thickness,
completion_percentage=1.0,
radius=radius,
mode="ngon"
),
color=inner_color
)
self.outer_circle = Entity(
parent=self,
model=Circle(
thickness=thickness,
completion_percentage=completion_percentage,
radius=radius,
mode="ngon"
),
color=outer_color
)
self.inner_circle = Entity(
parent=self,
model=Circle(
thickness=thickness,
completion_percentage=1.0,
radius=radius - .03,
mode="ngon"
),
color=inner_color
)
self.text = Text(parent=self, text=text, origin=(0, 0), scale=1.5)
def set_completion_percentage(self, completion_percentage=1.0):
if completion_percentage < 0.02:
self.outer_circle.visible = False
else:
self.outer_circle.visible = True
self.outer_circle.model = Circle(
thickness=self.thickness,
completion_percentage=completion_percentage,
radius=self.radius,
mode="ngon"
)
def set_text(self, text):
self.text.text = text
if __name__ == '__main__':
app = Ursina()
e = ProgressCircle(position=(0, 0), thickness=20, completion_percentage=0.02, radius=.1, color=color.lime)
app.run()