本文整理汇总了Python中mobject.vectorized_mobject.VGroup.to_corner方法的典型用法代码示例。如果您正苦于以下问题:Python VGroup.to_corner方法的具体用法?Python VGroup.to_corner怎么用?Python VGroup.to_corner使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mobject.vectorized_mobject.VGroup
的用法示例。
在下文中一共展示了VGroup.to_corner方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TeacherStudentsScene
# 需要导入模块: from mobject.vectorized_mobject import VGroup [as 别名]
# 或者: from mobject.vectorized_mobject.VGroup import to_corner [as 别名]
class TeacherStudentsScene(Scene):
def setup(self):
self.teacher = Mortimer()
self.teacher.to_corner(DOWN + RIGHT)
self.teacher.look(DOWN+LEFT)
self.students = VGroup(*[
Randolph(color = c)
for c in BLUE_D, BLUE_C, BLUE_E
])
self.students.arrange_submobjects(RIGHT)
self.students.scale(0.8)
self.students.to_corner(DOWN+LEFT)
self.teacher.look_at(self.students[-1].eyes)
for student in self.students:
student.look_at(self.teacher.eyes)
for pi_creature in self.get_everyone():
pi_creature.bubble = None
self.add(*self.get_everyone())
def get_teacher(self):
return self.teacher
def get_students(self):
return self.students
def get_everyone(self):
return [self.get_teacher()] + list(self.get_students())
def get_bubble_intro_animation(self, content, bubble_type,
pi_creature,
**bubble_kwargs):
bubble = pi_creature.get_bubble(bubble_type, **bubble_kwargs)
bubble.add_content(content)
bubble.resize_to_content()
if pi_creature.bubble:
content_intro_anims = [
Transform(pi_creature.bubble, bubble),
Transform(pi_creature.bubble.content, bubble.content)
]
else:
content_intro_anims = [
FadeIn(bubble),
Write(content),
]
pi_creature.bubble = bubble
return content_intro_anims
def introduce_bubble(self, content, bubble_type, pi_creature,
target_mode = None,
added_anims = [],
**bubble_kwargs):
if all(map(lambda s : isinstance(s, str), content)):
content = TextMobject(*content)
elif len(content) == 1 and isinstance(content[0], Mobject):
content = content[0]
else:
raise Exception("Invalid content type")
anims = []
#Remove other bubbles
for p in self.get_everyone():
if (p.bubble is not None) and (p is not pi_creature):
anims += [
FadeOut(p.bubble),
FadeOut(p.bubble.content)
]
p.bubble = None
anims.append(ApplyMethod(p.change_mode, "plain"))
#Bring in new bubble
anims += self.get_bubble_intro_animation(
content, bubble_type, pi_creature, **bubble_kwargs
)
#Add changing mode
if not target_mode:
if bubble_type is "speech":
target_mode = "speaking"
else:
target_mode = "pondering"
anims.append(
ApplyMethod(
pi_creature.change_mode,
target_mode,
)
)
self.play(*anims + added_anims)
return pi_creature.bubble
def teacher_says(self, *content, **kwargs):
return self.introduce_bubble(
content, "speech", self.get_teacher(), **kwargs
)
def student_says(self, *content, **kwargs):
if "target_mode" not in kwargs:
target_mode = random.choice([
"raise_right_hand",
"raise_left_hand",
])
kwargs["target_mode"] = target_mode
#.........这里部分代码省略.........
示例2: TeacherStudentsScene
# 需要导入模块: from mobject.vectorized_mobject import VGroup [as 别名]
# 或者: from mobject.vectorized_mobject.VGroup import to_corner [as 别名]
class TeacherStudentsScene(PiCreatureScene):
CONFIG = {
"student_colors" : [BLUE_D, BLUE_C, BLUE_E],
"student_scale_factor" : 0.8,
"seconds_to_blink" : 2,
}
def create_pi_creatures(self):
self.teacher = Mortimer()
self.teacher.to_corner(DOWN + RIGHT)
self.teacher.look(DOWN+LEFT)
self.students = VGroup(*[
Randolph(color = c)
for c in self.student_colors
])
self.students.arrange_submobjects(RIGHT)
self.students.scale(self.student_scale_factor)
self.students.to_corner(DOWN+LEFT)
self.teacher.look_at(self.students[-1].eyes)
for student in self.students:
student.look_at(self.teacher.eyes)
return [self.teacher] + list(self.students)
def get_teacher(self):
return self.teacher
def get_students(self):
return self.students
def teacher_says(self, *content, **kwargs):
return self.pi_creature_says(
self.get_teacher(), *content, **kwargs
)
def student_says(self, *content, **kwargs):
if "target_mode" not in kwargs:
target_mode = random.choice([
"raise_right_hand",
"raise_left_hand",
])
kwargs["target_mode"] = target_mode
student = self.get_students()[kwargs.get("student_index", 1)]
return self.pi_creature_says(
student, *content, **kwargs
)
def teacher_thinks(self, *content, **kwargs):
return self.pi_creature_thinks(
self.get_teacher(), *content, **kwargs
)
def student_thinks(self, *content, **kwargs):
student = self.get_students()[kwargs.get("student_index", 1)]
return self.pi_creature_thinks(student, *content, **kwargs)
def change_student_modes(self, *modes, **kwargs):
added_anims = kwargs.get("added_anims", [])
pairs = zip(self.get_students(), modes)
pairs = [(s, m) for s, m in pairs if m is not None]
start = VGroup(*[s for s, m in pairs])
target = VGroup(*[s.copy().change_mode(m) for s, m in pairs])
if "look_at_arg" in kwargs:
for pi in target:
pi.look_at(kwargs["look_at_arg"])
self.play(
Transform(
start, target,
submobject_mode = "lagged_start",
run_time = 2
),
*added_anims
)
def zoom_in_on_thought_bubble(self, bubble = None, radius = SPACE_HEIGHT+SPACE_WIDTH):
if bubble is None:
for pi in self.get_pi_creatures():
if hasattr(pi, "bubble") and isinstance(pi.bubble, ThoughtBubble):
bubble = pi.bubble
break
if bubble is None:
raise Exception("No pi creatures have a thought bubble")
vect = -bubble.get_bubble_center()
def func(point):
centered = point+vect
return radius*centered/np.linalg.norm(centered)
self.play(*[
ApplyPointwiseFunction(func, mob)
for mob in self.get_mobjects()
])