-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoRobots.py
76 lines (56 loc) · 2.71 KB
/
TwoRobots.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
from manim import *
class ImgPreview(Scene):
def construct(self):
background = ImageMobject("./assets/Space").scale(.5).set_opacity(.5)
self.add(background)
line = Line(10 * LEFT, 10 * RIGHT)
line.color = GREEN
self.add(line)
robot1 = SVGMobject("./assets/robot").scale(.3).shift(0.32 * UP + 3 * LEFT)
x1 = robot1.get_x()
flag1 = ImageMobject("./assets/parachute.png").scale(.1).shift(0.21 * UP + 3 * LEFT)
robot2 = SVGMobject("./assets/robot2").scale(.3).shift(0.32 * UP + 6 * LEFT)
x2 = robot2.get_x()
flag2 = ImageMobject("./assets/parachute.png").scale(.1).shift(0.21 * UP + 6 * LEFT)
self.add(flag1, robot1, flag2, robot2)
class TwoRobotsProblem(Scene):
def construct(self):
background = ImageMobject("./assets/Space").scale(.5).set_opacity(.5)
self.add(background)
line = Line(10 * LEFT, 10 * RIGHT)
line.color = GREEN
self.play(DrawBorderThenFill(line), run_time=3)
robot1 = SVGMobject("./assets/robot").scale(.3).shift(0.32 * UP + 3 * LEFT)
x1 = robot1.get_x()
flag1 = ImageMobject("./assets/parachute.png").scale(.1).shift(0.21 * UP + 3 * LEFT)
robot2 = SVGMobject("./assets/robot2").scale(.3).shift(0.32 * UP + 6 * LEFT)
x2 = robot2.get_x()
flag2 = ImageMobject("./assets/parachute.png").scale(.1).shift(0.21 * UP + 6 * LEFT)
self.play(FadeIn(flag1, robot1), FadeIn(flag2, robot2), run_time=3)
def roboMeet():
count = 0
Robot1ReachedParachute = False
Robot2ReachedParachute = False
while True:
if Robot1ReachedParachute:
self.play(
ApplyMethod(robot1.shift, .5*RIGHT, run_time=.5),
)
elif Robot2ReachedParachute:
self.play(
ApplyMethod(robot2.shift, .5*RIGHT, run_time=.5),
)
if abs(robot1.get_x() - robot2.get_x()) <= .3:
break
self.play(
ApplyMethod(robot1.shift, .5*RIGHT, run_time=.5),
ApplyMethod(robot2.shift, .5*RIGHT, run_time=.5),
)
count += 1
if abs(robot1.get_x() - x2) <= .3:
Robot1ReachedParachute = True
if abs(robot2.get_x()-x1) <= .3:
Robot2ReachedParachute = True
self.wait(.5)
roboMeet()
self.wait(2)