manim 将圆点添加到圆列表

manim add dots to circle list

我正在尝试围绕一个较大的圆圈创建一堆圆圈,而较小的圆圈需要添加点。然而,我正在努力添加点。

我相信这是因为循环中的对象是一个 mobject 而不是一个圆,但我不知道如何转换它,如果这确实是我的问题。

如果可以请帮忙

# manim scene.py PathExample
from manim import *

class PathExample(Scene):
    def construct(self):
        num_points = 16
        angles = [n * (360 / num_points) for n in range(num_points)]

        outer_circle = Circle(color=RED, radius=3)
        circles = [Circle(color=RED, radius=1).shift(4*LEFT).move_to(
        outer_circle.point_at_angle(n*DEGREES)) for n in angles]

        dots1 = []
        for c in circles:
            c.add_updater(lambda m: m.rotate(-0.01))
            dot = Dot(color=RED, radius=0, stroke_width=0).move_to(
                Circle(c).point_at_angle(0*DEGREES))
            dots1.append(dot)

        # # First attempt
        # dots1 = [Dot(color=RED, radius=0, stroke_width=0).move_to(
        #     c.point_at_angle(0*DEGREES)) for c in circles]

        rolling_outer_circle = VGroup(
            outer_circle, *circles)

        rolling_outer_circle.add_updater(lambda m: m.rotate(-0.01))
        self.add(rolling_outer_circle, outer_circle)
        self.play(rolling_outer_circle.animate, run_time=10, rate_func=linear)
        self.wait()

正在执行 manim scene1.py 路径示例

我不知道为什么,但主要问题是 point_at_angle(0*DEGREES) - 在某些情况下它会给出错误的结果。

如果我将 n*DEGREESfor c, n in zip(circles, angles): 一起使用,那么它会起作用。

另一个问题是 radius=.1, stroke_width=0Dot 是不可见的,所以它需要 ie。 radius=.1


最少的工作代码

from manim import *

class PathExample(Scene):

    def construct(self):
        num_points = 16
        
        angles = [n * (360 / num_points) for n in range(num_points)]

        outer_circle = Circle(color=RED, radius=3)
        
        circles = [Circle(color=RED, radius=1).move_to(outer_circle.point_at_angle(n*DEGREES)) 
                    for n in angles]

        dots = []
        for c, n in zip(circles, angles):
            #c.add_updater(lambda m: m.rotate(-0.01))
            dot = Dot(color=RED, radius=.1, stroke_width=0).move_to(c.point_at_angle(n*DEGREES))
            dots.append(dot)

        # # First attempt
        #dots = [Dot(color=RED, radius=.1, stroke_width=0).move_to(c.point_at_angle(n*DEGREES)) 
        #            for c, n in zip(circles, angles)]

        rolling_outer_circle = VGroup(outer_circle, *circles, *dots)

        rolling_outer_circle.add_updater(lambda m: m.rotate(-0.01))
        
        self.add(rolling_outer_circle, outer_circle, *dots)
        self.play(rolling_outer_circle.animate, run_time=10, rate_func=linear)
        self.wait()
                
if __name__ == '__main__':
    import subprocess
    subprocess.run(['manim', '-p', '-ql', __file__, 'PathExample'])

结果(部分动画):