/
SR_arrow.py
85 lines (69 loc) · 2.37 KB
/
SR_arrow.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 manim import *
PROPOSED = 1
REJECTED = 2
ACCEPTED = 3
class SRArrow():
def __init__(self, start, end, stroke_width, tip_length,
proposed_z_index = 0, state=PROPOSED):
self.start = start
self.end = end
self.stroke_width = stroke_width
self.tip_length = tip_length
self.state = state
assert state in [PROPOSED, REJECTED, ACCEPTED]
self.accepted = Arrow(
start=self.start,
end=self.end,
stroke_width=self.stroke_width,
tip_length=self.tip_length,
max_stroke_width_to_length_ratio=10000,
max_tip_length_to_length_ratio=10000,
z_index = 1,
color=GREEN
)
self.accepted.tip.z_index = 1
self.proposed = Arrow(
start=self.start,
end=self.end,
stroke_width=self.stroke_width,
tip_length=self.tip_length,
max_stroke_width_to_length_ratio=10000,
max_tep_length_to_length_ratio=10000,
z_index = proposed_z_index,
color=WHITE
)
self.proposed.tip.z_index = proposed_z_index
self.proposed = DashedVMobject(self.proposed)
self.rejected = Arrow(
start=self.start,
end=self.end,
stroke_width=self.stroke_width,
tip_length=self.tip_length,
max_stroke_width_to_length_ratio=10000,
max_tip_length_to_length_ratio=10000,
z_index = -1,
color=GREY_E
)
self.rejected.tip.z_index = 1
def curr_arrow(self):
if self.state == ACCEPTED:
return self.accepted
elif self.state == REJECTED:
return self.rejected
elif self.state == PROPOSED:
return self.proposed
def propose(self):
self.state = PROPOSED
return Create(self.proposed)
def reject(self):
curr = self.curr_arrow()
self.state = REJECTED
return ReplacementTransform(curr, self.rejected)
def accept(self):
curr = self.curr_arrow()
self.state = ACCEPTED
return ReplacementTransform(curr, self.accepted)
def mobjects(self):
arrows = [self.accepted, self.rejected, self.proposed]
arrows.extend(a.tip for a in arrows if hasattr(a, "tip"))
return arrows