本文整理汇总了Python中scene.GraphScene.construct方法的典型用法代码示例。如果您正苦于以下问题:Python GraphScene.construct方法的具体用法?Python GraphScene.construct怎么用?Python GraphScene.construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scene.GraphScene
的用法示例。
在下文中一共展示了GraphScene.construct方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: construct
# 需要导入模块: from scene import GraphScene [as 别名]
# 或者: from scene.GraphScene import construct [as 别名]
def construct(self):
GraphScene.construct(self)
paths = [(1, 2, 4, 5, 6), (6, 7, 1, 3)]
non_paths = [[(0, 1), (7, 8), (5, 6)], [(5, 0), (0, 2), (0, 1)]]
valid_path = TextMobject("Valid \\\\ Path").highlight("green")
not_a_path = TextMobject("Not a \\\\ Path").highlight("red")
for mob in valid_path, not_a_path:
mob.to_edge(UP)
kwargs = {"run_time": 1.0}
for path, non_path in zip(paths, non_paths):
path_lines = Mobject(
*[
Line(self.points[path[i]], self.points[path[i + 1]]).highlight("yellow")
for i in range(len(path) - 1)
]
)
non_path_lines = Mobject(
*[Line(self.points[pp[0]], self.points[pp[1]]).highlight("yellow") for pp in non_path]
)
self.remove(not_a_path)
self.add(valid_path)
self.play(ShowCreation(path_lines, **kwargs))
self.dither(2)
self.remove(path_lines)
self.remove(valid_path)
self.add(not_a_path)
self.play(ShowCreation(non_path_lines, **kwargs))
self.dither(2)
self.remove(non_path_lines)
示例2: construct
# 需要导入模块: from scene import GraphScene [as 别名]
# 或者: from scene.GraphScene import construct [as 别名]
def construct(self):
GraphScene.construct(self)
self.generate_dual_graph()
self.add(TextMobject("Duality").to_edge(UP))
self.remove(*self.vertices)
def special_alpha(t):
if t > 0.5:
t = 1 - t
if t < 0.25:
return smooth(4*t)
else:
return 1
kwargs = {
"run_time" : 5.0,
"rate_func" : special_alpha
}
self.play(*[
Transform(*edge_pair, **kwargs)
for edge_pair in zip(self.edges, self.dual_edges)
] + [
Transform(
Mobject(*[
self.vertices[index]
for index in cycle
]),
dv,
**kwargs
)
for cycle, dv in zip(
self.graph.region_cycles,
self.dual_vertices
)
])
self.dither()