其他分享
首页 > 其他分享> > hex

hex

作者:互联网

%%manim -v WARNING -qh s1
class s1(ThreeDScene):
    def construct(self):
        n1 = Text('在正六边形中,各个内角为120°').to_edge(DOWN).scale(0.7)
        n2 = Text('但是sp³杂化的碳原子正常键角为109°').to_edge(DOWN).scale(0.7)
        n3 = Text('事实上,环己烷的六个碳原子不在同一平面上').to_edge(DOWN).scale(0.7)
        n4 = Text('这样可以保持sp³杂化的正常键角').to_edge(DOWN).scale(0.7)
        c_tetrahedron = Tetrahedron(edge_length=4)
        center_c = MathTex('C').scale(1).move_to(c_tetrahedron.get_center())
        tet_line1 = DashedLine(start=c_tetrahedron.get_corner(DR), end=center_c.get_center())
        tet_line2 = DashedLine(start=c_tetrahedron.get_corner(DL), end=center_c.get_center())
        tet_line3 = DashedLine(start=c_tetrahedron.get_corner(UR), end=center_c.get_center())
        tet_line4 = DashedLine(start=c_tetrahedron.get_corner(UL), end=center_c.get_center())
        vg_tet = VGroup(c_tetrahedron,center_c)
        vg_tet_line = VGroup(tet_line1, tet_line2, tet_line3, tet_line4)
        self.play(Write(c_tetrahedron),Write(center_c),run_time=1.5)
        self.play(DrawBorderThenFill(n1))
        self.play(Transform(n1, n2))
        self.play(Write(vg_tet_line))
        tet_arc = Angle(tet_line2,tet_line1,radius=0.4)
        tet_arc_number = Text('109º28´',font="STZhongsong").scale(0.6).next_to(tet_arc.get_center()+0.2*UP)  
        vg_tet_line_arc = VGroup(tet_line1, tet_line2, tet_line3, tet_line4, tet_arc, tet_arc_number)
        self.play(Write(tet_arc), Write(tet_arc_number))
        self.play(FadeOut(vg_tet_line_arc), FadeOut(n1))
        self.play(Rotate(vg_tet, angle=2*PI,axis=np.array([0,1,0])), run_time=4)
        self.play(FadeOut(vg_tet))
        
        d1 = Dot(radius=0.1).move_to(np.array([2,0,0])).set_color(RED)
        d2 = d1.copy().rotate(about_point=np.array([0,0,0]), angle=60*DEGREES).set_color(TEAL)
        d3 = d2.copy().rotate(about_point=np.array([0,0,0]), angle=60*DEGREES).set_color(TEAL)
        d4 = d3.copy().rotate(about_point=np.array([0,0,0]), angle=60*DEGREES).set_color(RED)
        d5 = d4.copy().rotate(about_point=np.array([0,0,0]), angle=60*DEGREES).set_color(TEAL)
        d6 = d5.copy().rotate(about_point=np.array([0,0,0]), angle=60*DEGREES).set_color(TEAL)
        dvg = VGroup(d1,d2,d3,d4,d5,d6)
        self.play(Write(dvg))
        l1 = Line(d1.get_center(),d2.get_center()).add_updater(lambda z: z.become(Line(d1.get_center(),d2.get_center())))
        l2 = Line(d2.get_center(),d3.get_center()).add_updater(lambda z: z.become(Line(d2.get_center(),d3.get_center())))
        l3 = Line(d3.get_center(),d4.get_center()).add_updater(lambda z: z.become(Line(d3.get_center(),d4.get_center())))
        l4 = Line(d4.get_center(),d5.get_center()).add_updater(lambda z: z.become(Line(d4.get_center(),d5.get_center())))
        l5 = Line(d5.get_center(),d6.get_center()).add_updater(lambda z: z.become(Line(d5.get_center(),d6.get_center())))
        l6 = Line(d6.get_center(),d1.get_center()).add_updater(lambda z: z.become(Line(d6.get_center(),d1.get_center())))
        lvg = VGroup(l1,l2,l3,l4,l5,l6)
        self.play(Write(lvg), DrawBorderThenFill(n3))
        self.play(Transform(n3,n4))
        self.play(FadeOut(n3))
        vghex = VGroup(dvg,lvg)
        vt1 = ValueTracker(120)
        vt2 = ValueTracker(120)
        anglenum1 = DecimalNumber(unit="^{\circ}", color=RED).add_updater(lambda x: x.set_value(vt1.get_value())).next_to(d1)
        anglenum2 = DecimalNumber(unit="^{\circ}", color=TEAL).add_updater(lambda x: x.set_value(vt2.get_value())).next_to(d6, DOWN)
        self.play(Write(anglenum1),Write(anglenum2))
        self.wait(1.5)
        num1 = np.cos(54.4/180*PI) - np.cos(1/3*PI)
        num2 = np.cos(1/6*PI) - np.cos(35.5/180*PI)
        self.play(d1.animate.shift(num1*RIGHT),d4.animate.shift(num1*LEFT),d2.animate.shift(num2*DOWN),d3.animate.shift(num2*DOWN),d5.animate.shift(num2*UP),d6.animate.shift(num2*UP),vt1.animate.set_value(109),vt2.animate.set_value(125.5))
        self.wait(1)
        self.play(Rotate(vghex, angle=45*DEGREES, axis=np.array([1,0,0])), anglenum2.animate.shift(0.7*UP))
        self.wait()
        dl1 = DashedLine(start=d2,end=d6, dashed_ratio=0.3)
        dl2 = DashedLine(start=d3,end=d5, dashed_ratio=0.3)
        self.play(Write(dl1), Write(dl2))
        rvg1 = VGroup(d1,l1,l6)
        rvg2 = VGroup(d4,l3,l4)
        t1 = Text('椅型',font="STZhongsong").scale(0.7).to_edge(DOWN).shift(2*LEFT)
        t2 = Text('船型',font="STZhongsong").scale(0.7).to_edge(DOWN).shift(2*RIGHT)
        self.play(Rotate(rvg1, angle = -30*DEGREES, axis=dl1.get_unit_vector()), Rotate(rvg2, angle = -30*DEGREES, axis=dl2.get_unit_vector()), anglenum1.animate.shift(0.2*UP + 0.1*LEFT), vt2.animate.set_value(109))
        self.play(FadeIn(t1))
        self.wait(1)
        self.play(FadeOut(t1))
        self.play(Rotate(rvg1, angle = 30*DEGREES, axis=dl1.get_unit_vector()), Rotate(rvg2, angle = 30*DEGREES, axis=dl2.get_unit_vector()), anglenum1.animate.shift(0.2*DOWN + 0.1*RIGHT), vt2.animate.set_value(125.5))
        self.wait(1.5)
        self.play(Rotate(rvg1, angle = -30*DEGREES, axis=dl1.get_unit_vector()), Rotate(rvg2, angle = 30*DEGREES, axis=dl2.get_unit_vector()), anglenum1.animate.shift(0.2*UP + 0.1*LEFT), vt2.animate.set_value(109))
        self.play(FadeIn(t2))
        self.wait(1)
        self.play(FadeOut(t2))
        vgall = VGroup(dvg, lvg, dl1, dl2, anglenum1, anglenum2)
        self.play(FadeOut(vgall))
        self.play(FadeIn(t1), FadeIn(t2))

 

标签:play,center,get,self,hex,animate,tet
来源: https://www.cnblogs.com/daxiangcai/p/16464189.html