-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobj_group.py
More file actions
67 lines (55 loc) · 2.33 KB
/
Copy pathobj_group.py
File metadata and controls
67 lines (55 loc) · 2.33 KB
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
from manim import *
def rotating_angle(angle:Angle, text:Mobject, tracker: ValueTracker,buffer = 4 * SMALL_BUFF):
'''Creates a group of angle and it's lines, that can be updated by changing ValueTrackers value.'''
def move_text(center):
dir_vect = angle.point_from_proportion(0.5) - center
offset_vect = ( angle.radius + buffer) * (dir_vect / np.linalg.norm(dir_vect))
text.move_to(center + offset_vect)
static_l, mov_line = angle.lines
group = VGroup(static_l, mov_line,text,angle)
move_text(mov_line.get_start())
def closure(x:VGroup):
center = mov_line.get_start()
mov_line.rotate(
tracker.get_value() * DEGREES - mov_line.get_angle(),
about_point=center
)
angle.become(Angle(static_l, mov_line, radius= angle.radius, other_angle=False))
move_text(center)
group.add_updater(closure)
return group
class MovingAngle(Scene):
def construct(self):
trc = ValueTracker(110)
line1 = Line(LEFT, RIGHT)
line_moving = Line(LEFT, RIGHT*4)
line_moving.rotate(trc.get_value() * DEGREES, about_point=line_moving.get_start())
angle_obj = Angle(line1, line_moving, radius=0.5, other_angle=False)
number = DecimalNumber(trc.get_value(), num_decimal_places=0)
number.add_updater(lambda o: DecimalNumber.set_value(o, trc.get_value()))
angle_group = rotating_angle(angle_obj,number,trc,)
self.wait()
self.add(angle_group)
for a in range(1,40,10):
self.play(trc.animate.set_value(a))
line_moving.set_color(BLUE)
for a in [50,30,60,180]:
self.play(trc.animate.set_value(a))
self.wait(.5)
line_moving.set_color(RED)
for _ in range(4):
self.play(trc.animate.increment_value(10))
self.wait(.5)
a = trc.get_value()
line_moving.set_color(YELLOW)
angle_obj.radius = 1
while a < 360:
a += 35
self.play(trc.animate.set_value(a))
self.wait(.5)
line_moving.set_color(TEAL)
self.play(angle_obj.animate.set(radius= 0.5))
self.play(angle_group.animate.move_to(RIGHT*3))
for a in np.linspace(1.9*PI,0.5*PI,5):
self.play(trc.animate.set_value(a/DEGREES))
self.wait(.5)