首页 > 其他分享 >Single electron atomic structure

Single electron atomic structure

时间:2022-09-23 18:36:25浏览次数:36  
标签:xxp return color args electron Single structure kwargs def

函数

#         预定义
        if True:
            r = RIGHT;l = LEFT;d = DOWN;u = UP;du = DEGREES;rr = RED;bb = BLUE;gg = GREEN;gg2 = GOLD;pp = PINK;tt = TEAL;h = SVGMobject("D:\manimSVG\constants\h.svg");h2o = SVGMobject("D:\manimSVG\constants\h2o.svg");
#         xxp
        if type('xxp') == str:
    #         xxp transform
            def xt(names, *args):
                def pretrans0(name, i):
                    if type(i) == int:
                        back = name + '[' + str(i) + ']'
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = i[0:m]
                        n2 = i[m+1:]
                        back = name + '[' + n1 + ':' + n2 + ']'
                    return back

                def pretrans(name, i):
                    if type(i) == int:
                        back = name + '[' + str(i) + ']'
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = i[0:m]
                        n2 = i[m+1:]
                        back = name + '[' + n1 + ':' + n2 + ']'
                    elif type(i) == list:
                        back = 'VGroup('
                        for j in i:
                            item = pretrans0(name, j) + ','
                            back += item
                        back += ')'
                    return back

                ag = 'AnimationGroup('
            #           range(0, n-1)是错的
                itemli = []
                for l in names:
                    itemli.append(list(range(len(l))))
                def countli0(name, i):
                    if type(i) == int:
                        name.remove(i)
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = int(i[0:m])
                        n2 = int(i[m+1:])-1
                        p1 = name.index(n1)
                        p2 = name.index(n2)
                        del name[p1:p2+1]
                
                def countli(name, i):
                    if type(i) == int:
                        name.remove(i)
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = int(i[0:m])
                        n2 = int(i[m+1:])-1
                        p1 = name.index(n1)
                        p2 = name.index(n2)
                        del name[p1:p2+1]
                    elif type(i) == list:
                        for j in i:
                            item = countli0(name, j)
                            
                set1 = set()
                set2 = set()
                            
                for m in range(len(args)):
                    n = 0
                    for i in args[m][2]:
                        n += 1
                        if n % 2 != 0:
                            u = pretrans(f'names[args[{str(m)}][0]]', i)
                            countli(itemli[args[m][0]], i)
                            set1.add(args[m][0])
                        else:
                            v = pretrans(f'names[args[{str(m)}][1]]', i)
                            item = f'Transform({u}, {v}),'
                            ag += item
                            countli(itemli[args[m][1]], i)
                            set2.add(args[m][1]) 
                            
                for i in set1:
                    for ii in itemli[i]:
#                         reverse GrowFromCenter不可用
                        ag += f'ShrinkToCenter(names[{str(i)}][{str(ii)}]), '
                for j in set2:
                    for jj in itemli[j]:
                        ag += f'GrowFromCenter(names[{str(j)}][{str(jj)}]), '

                ag += ')'
                agg = eval(ag)
                return agg
    #         xxp transform 2
            def xt2(a, b, c):
                def pretrans0(name, i):
                    if type(i) == int:
                        back = name + '[' + str(i) + ']'
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = i[0:m]
                        n2 = i[m+1:]
                        back = name + '[' + n1 + ':' + n2 + ']'
                    return back

                def pretrans(name, i):
                    if type(i) == int:
                        back = name + '[' + str(i) + ']'
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = i[0:m]
                        n2 = i[m+1:]
                        back = name + '[' + n1 + ':' + n2 + ']'
                    elif type(i) == list:
                        back = 'VGroup('
                        for j in i:
                            item = pretrans0(name, j) + ','
                            back += item
                        back += ')'
                    return back

                n = 0
                ag = 'AnimationGroup('
            #           range(0, n-1)是错的
                for i in c:
                    n += 1
                    if n % 2 != 0:
                        u = pretrans('a', i)
                    else:
                        v = pretrans('b', i)
                        item = f'Transform({u}, {v}),'
                        ag += item
                ag += ')'
                agg = eval(ag)
                return agg
#             xxp transform 3
            def xt3(a,b):
                x=b.get_center()-a.get_center()
                y=b.width/a.width
                return AnimationGroup(a.animate.shift(x).scale(y))
    #         xxp color to hex
            def xc2h(c):
                return rgb_to_hex(color_to_rgb(c))
#             xxp color and opacity init
            def xcoi(*args):
                for a in args:
#                     先缩放再设置透明度(否则会消失不见)
                    a.set_opacity(1)
                    for i in a:
                        if xc2h(i.color) == '#ff0000':
                            i.set_color(RED).set_sheen(0.1)
                        elif xc2h(i.color) == '#ffff00':
                            i.set_color(GOLD).set_sheen(0.1)
                        elif xc2h(i.color) == '#00ff00':
                            i.set_color(GREEN).set_sheen(0.1)
                        elif xc2h(i.color) == '#00ffff':
                            i.set_color(TEAL).set_sheen(0.1)
                        elif xc2h(i.color) == '#0000ff':
                            i.set_color(BLUE).set_sheen(0.1)
                        elif xc2h(i.color) == '#ff00ff':
                            i.set_color(PINK).set_sheen(0.1)
    #         xxp opacity scale
            def xos(num, *args):
#             最好让透明度也一样
                def premovescale(a, b):
#                     x = VGroup()
#                     y = VGroup()
                    for i in a:
#                         设置get_fill_opacity() == 0.5会失效
                        if i.get_fill_opacity() < 1:
                            x = i
#                             x.add(i)
                    for j in b:
                        if j.get_fill_opacity() < 1:
                            y = j
#                             y.add(j)
                    scale = y.height/x.height
                    a.scale(scale)
#                     先缩放再移动
                    vector  = y.get_center() - x.get_center()
                    a.shift(vector)
                args[0].scale(num)
                for n in range(len(args) - 1):
                    premovescale(args[n+1], args[n])
                xcoi(*args)
    #         xxp check
            def xc(*args):
                self.camera.background_color = WHITE
                for svg in args:
                    if type(svg) == list:
                        self.clear()
                        for sss in svg:
                            self.add(sss.set(color = RED))
                        for sss in svg:
                            n = 0
                            for i in sss:
                                num = Integer(number=n, stroke_width=2).set_color(BLACK).move_to(i)
                                n += 1
                                self.add(num)
                        self.wait()
                    else:
                        self.clear()
                        self.add(svg.set(color = RED))
                        n = 0
                        for i in svg:
                            num = Integer(number=n, stroke_width=2).set_color(BLACK).move_to(i)
                            n += 1
                            self.add(num)
                        self.wait()
                self.clear()
    #         xxp find
            def xf(a, b):
                n1 = str.find(a.text, b)
                n2 = n1 + len(b)
                return a[n1:n2]
    #         xxp narrator
            def xn(a):
                text = Text(a, font='STZhongsong').to_edge(DOWN).scale(0.6)
                return text
    #         xxp narrator 2
            def xn2(a):
                text = Text(a, font='STFangsong').scale(0.7).to_edge(DOWN)
                return text
    #         xxp upnarrator
            def xun(a):
                text = Text(a, font='STZhongsong').to_edge(UP).scale(0.8)
                return text
    #         xxp para
            def xp(x, y):
                a = Text(y, font="STZhongsong").to_edge(DOWN).scale(0.6)
                b = Text(x, font="STZhongsong").to_edge(1.8*DOWN).scale(0.6)
                return VGroup(a, b)
    #         xxp scale
            def xs(a, n1, b, n2):
                scale = b[n2].width/a[n1].width
                a.scale(scale)
    #         xxp move
            def xm(a, n1, b, n2):
                vect = b[n2].get_center() - a[n1].get_center()
                a.shift(vect)
    #         xxp move and scale
            def xms(a, n1, b, n2):
                scale = b[n2].width/a[n1].width
                a.scale(scale)
                vect = b[n2].get_center() - a[n1].get_center()
                a.shift(vect)
    #         xxp choose color
            def xcc(a, b):
                for i in a:
                    if rgb_to_hex(color_to_rgb(i.color)) == b:
                        return i
    #         xxp narrator wait
            def xnw(a):
                self.wait(0.1*len(a))
    #         xxp text flower
            def xtf(a):
                at = Text(a, font = 'STZhongsong',stroke_width=2).set_color(color = ['#f3e9e0', '#fea8a9'])
    #             at[0].set_color(color = ['#f3e9e0', '#fea8a9'])
    #             at[1].set_color(color = ['#f3e9e0', '#fea8a9'])
                fl = msm('icon')[8].rotate(PI/2).set_color(color = ['#fea8a9', '#f3e9e0']).scale(1.5)
                at.next_to(fl, RIGHT)
                vg = VGroup(fl, at)
                vg.set(height = 0.6).to_corner(UL)
                return vg
    #         xxp text flower2
            def xtf2(judge, a):
                if judge == 1:
                    at = Text(a, font = 'STFangsong',stroke_width=2).set_color(color = ['#f3e9e0', '#b1d85c'])
                elif judge == 2:
#                 一般不是中文
                    at = MarkupText(a, stroke_width=2).set_color(color = ['#f3e9e0', '#b1d85c'])
    #             at[0].set_color(color = ['#f3e9e0', '#fea8a9'])
    #             at[1].set_color(color = ['#f3e9e0', '#fea8a9'])
                fl = msm('icon')[8].rotate(PI/2).set_color(color = ['#b1d85c', '#f3e9e0']).scale(1.5)
                at.next_to(fl, RIGHT)
                vg = VGroup(fl, at)
                vg.set(height = 0.6).to_corner(UL).shift(2*RIGHT)
                return vg
    #         xxp text flower3
            def xtf3(a):
                at = Text(a, font = 'STZhongsong',stroke_width=2).set_color(color = ['#ccffff', '#afccff'])
    #             at[0].set_color(color = ['#f3e9e0', '#fea8a9'])
    #             at[1].set_color(color = ['#f3e9e0', '#fea8a9'])
                fl = msm('icon')[8].rotate(PI/2).set_color(color = ['#afccff', '#ccffff']).scale(1.5)
                at.next_to(fl, RIGHT)
                vg = VGroup(fl, at)
                vg.set(height = 0.6).to_corner(UL).shift(2*DOWN)
                return vg
    #         xxp color move and scale
            def xcms(a, b):
                x = VGroup()
                y = VGroup()
                for i in a:
                    if rgb_to_hex(color_to_rgb(i.color)) == '#000000':
                        x.add(i)
                for j in b:
                    if rgb_to_hex(color_to_rgb(j.color)) == '#000000':
                        y.add(j)
                scale = y.width/x.width
                vect = y.get_center() - x.get_center()
                a.shift(vect)
                a.scale(scale)
    #         xxp single scale
            def xss(a, n):
                x = Text('C', font="Times New Roman")
                y = a[n]
                scale = x.width/y.width
                a.scale(scale)
    #         xxp pre postion
            def xpp(a, pos):
                d1 = Dot().to_corner(UL)
                d2 = Dot().to_edge(UP)
                d3 = Dot().to_corner(UR)
                d4 = Dot().to_edge(LEFT)
                d5 = Dot()
                d6 = Dot().to_edge(RIGHT)
                d7 = Dot().to_corner(DL)
                d8 = Dot().to_edge(DOWN)
                d9 = Dot().to_corner(DR)
                if pos == 'ul':
                    a.move_to((d1.get_center() + d5.get_center())/2)
                elif pos == 'u':
                    a.move_to((d2.get_center() + d5.get_center())/2)
                elif pos == 'ur':
                    a.move_to((d3.get_center() + d5.get_center())/2)
                elif pos == 'l':
                    a.move_to((d4.get_center() + d5.get_center())/2)
                elif pos == 'o':
                    a.move_to(d5.get_center())
                elif pos == 'r':
                    a.move_to((d6.get_center() + d5.get_center())/2)
                elif pos == 'dl':
                    a.move_to((d7.get_center() + d5.get_center())/2)
                elif pos == 'd':
                    a.move_to((d8.get_center() + d5.get_center())/2)
                elif pos == 'dr':
                    a.move_to((d9.get_center() + d5.get_center())/2)
#             xxp arrange and align
            def xaa(mobs, b, d):
                vg = VGroup()
                for m in mobs:
                    vg.add(m)
                vg.arrange(buff=b)
                if d == 'u':
                    dire = UP
                elif d == 'd':
                    dire = DOWN
                for i in mobs:
                    if i != mobs[0]:
                        i.align_to(mobs[0], dire)
#             xxp add other
            def xao(*args):
                if len(args) == 2:
                    sa(args[0].to_corner(UR), args[1].to_corner(DL))
                if len(args) == 3:
                    sa(args[0].to_corner(UR), args[1].to_corner(DL), args[2].to_corner(DR))
#             xxp grow from center
            def xgf(a, li):
                avg = 'AnimationGroup('
                def pregrow(name, i):
                    if type(i) == int:
                        back = name + '[' + str(i) + ']'
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = i[0:m]
                        n2 = i[m+1:]
                        back = name + '[' + n1 + ':' + n2 + ']'
                    return back
                for j in li:
                    partani = pregrow('a', j)
                    avg += f'GrowFromCenter({partani}), '
                avg += ')'
                return eval(avg)
#             xxp reverse grow from center
            def xrgf(a, li):
                avg = 'AnimationGroup('
                def pregrow(name, i):
                    if type(i) == int:
                        back = name + '[' + str(i) + ']'
                    elif type(i) == str:
                        m = i.find('.')
                        n1 = i[0:m]
                        n2 = i[m+1:]
                        back = name + '[' + n1 + ':' + n2 + ']'
                    return back
                for j in li:
                    partani = pregrow('a', j)
                    avg += f'GrowFromCenter({partani}, reverse_rate_function = True), '
                avg += ')'
                return eval(avg)
#             xxp color and sheen static
            def xcss(a, b):
                a.set_color(b).set_sheen(0.1)
#             xxp place in line
            def xpl(*args):
                vg = VGroup()
                frame = FullScreenRectangle()
                wid = frame.width
                for i in args:
                    vg.add(i.copy())
                    wid -= i.width
                mybuff = wid/(len(args)+1)
                vg.arrange(buff=mybuff)
                for j in range(len(args)):
                    args[j].match_x(vg[j])
#             xxp place in grid
            def xpg(*args):
                n = 0
                full = FullScreenRectangle()
                li = ['ul','ur','dl','dr']
                for a in args:
                    if a.width > a.height:
                        a.set(width = full.width/3)
                        xpp(a,li[n])
                    else:
                        a.set(height = full.height/3)
                        xpp(a,li[n])
                    n += 1             
#             xxp color 1
            def xc1(*args):
                for a in args:
                    a.save_state()
                    a.set_color(WHITE).set_sheen(0)
#             xxp color 2
            def xc2(*args):
                li = []
                for a in args:
                    li.append(Restore(a))
                return li
#             xxp color 3
            def xc3(*args):
                li = []
                for a in args:  # 不可使用animate
                    li.append(ApplyMethod(a.set_color, WHITE))
                return li
#             xxp animations list
            def xal(t,*argss):
                args = []
                for i in argss:
                    args.append(i)
#                 不是args = atgs.reverse()
                args.reverse()
                n = 0
                for a in args:
                    if n == 1:
                        ag = AnimationGroup(args[1],args[0],lag_ratio=t)
                    elif n > 1:
                        ag = AnimationGroup(a,ag,lag_ratio=t)
                    n += 1
                return ag         
#             xxp sub number
            def xsn(*args):
                vg = VGroup()
                for i in range(len(args)):
                    n = Integer(i+1).next_to(args[i],0.7*UP)
                    xcss(n, BLUE)
                    vg.add(n)
                return vg
#             xxp get distance
            def xgd(a,b):
                return b.get_center() - a.get_center()
#             xxp get distance by coodrdinate
            def xgdc(a,b):
                return b - a.get_center()
#             xxp text flower list
            def xtfl(a,*args):
#                 for a in args:
                vg = VGroup()
                li0 = xtf(a)
                vg.add(li0)
                n = 1
                for a in args:
                    li = xtf2(1,a)
                    xm(li,0,li0,0);li.shift(n*0.9*DOWN+RIGHT)
                    vg.add(li)
                    n += 1
                return vg
#             xxp text flower list abbr
            def xtfla(a,b):
#                 for a in args:
                vg = VGroup()
                li0 = xtf(a)
                n = 1
                li1 = xtf2(1,'');xm(li1,0,li0,0);li1.shift(DOWN+RIGHT)
                vg.add(li0,li1)
                for i in range(b-1):
                    li = xtf2(1,'')
                    xm(li,0,li1,0);li.shift(n*0.2*DOWN)
                    vg.add(li)
                    n += 1
                return vg
#             xxp corner check
            def xcc(a,b):
                a.to_corner(UL);b.to_corner(DR)
                xc([a,b])
#             xxp edge check
            def xec(a,b):
                a.to_edge(UP);b.to_edge(DOWN)
                xc([a,b])
#             xxp grid check
            def xgc(*args):
                xpg(*args)
                xc([*args])
#             xxp orbit color
            def xoc(a):
                a.set_color([BLUE_C, BLUE_E]).set_sheen(0.3).set_opacity(0.8)
#             xxp play
            def xxp(*args):
                for a in args:
                    if type(a) == list:
                        self.wait(0.5)
                        self.play(*a)
                        self.wait(0.5)
                    elif type(a) == set:
                        self.clear()
                        self.add(*a)
                    elif type(a) == tuple:
                        for i in a:
                            self.play(i)
                    else:
                        self.wait(0.5)
                        self.play(a)
                        self.wait(0.5)
#             xxp molecule move
            def xmm(a,b,c):
                return a.animate.shift(xgd(b,c))
#             xxp markup text
            def xmt(a):
#                 最多不能超过三个
                for i in range(5):

                    a = a.replace('_','<sub>',1)
                    a = a.replace('_','</sub>',1)
                    a = a.replace('^','<sup>',1)
                    a = a.replace('^','</sup>',1)
                return MarkupText(a)
#             xxp move along arc
            def xmaa(a,b,c,s):
                arc = ArcBetweenPoints(b.get_center(), c.get_center(), angle = s*120*DEGREES)
                return MoveAlongPath(a, arc)
#             xxp dot group
            def xdg(num,r1,r2):
                vg = VGroup()
                for i in range(num):
                    r = np.random.rand()*(r2-r1) + r1
                    t = np.random.rand()*2*PI
                    vg.add(Circle(radius=0.02, color=BLUE_B, fill_opacity=1).shift(r*np.cos(t)*RIGHT+r*np.sin(t)*UP))
                return vg
#         manim CE
        if type('manim CE') == str:
    #         self.play()
            def sp(*args, **kwargs):
                return self.play(*args, **kwargs)
    #         self.wait()
            def sw(*args, **kwargs):
                return self.wait(*args, **kwargs)
    #         self.add()
            def sa(*args, **kwargs):
                return self.add(*args, **kwargs)
    #         self.clear()
            def sc(*args, **kwargs):
                return self.clear(*args, **kwargs)
    #         self.remove()
            def sr(*args, **kwargs):
                return self.remove(*args, **kwargs)

    #         Animation Transform()
            def at(a, b, *args, **kwargs):
                return ReplacementTransform(a, b, *args, **kwargs)
    #         Animation Transform()
            def at0(a, b, *args, **kwargs):
                return Transform(a, b, *args, **kwargs)
    #         Animation ReplacementTransform()
            def art(a, b, *args, **kwargs):
                return ReplacementTransform(a, b, *args, **kwargs)
        #         Animation TransformMatchingShapes()
            def atm(a, b, *args, **kwargs):
                return TransformMatchingShapes(a, b, *args, **kwargs)
    #         Animation ClockwiseTransform()
            def act(a, b, *args, **kwargs):
                return ClockwiseTransform(a, b, *args, **kwargs)
    #         Animation CounterclockwiseTransform()
            def acct(a, b, *args, **kwargs):
                return CounterclockwiseTransform(a, b, *args, **kwargs)
    #         Animation Write()
            def aw(a, *args, **kwargs):
                return Write(a, *args, **kwargs)
    #         Animation LaggedStart()
            def als(a, *args, **kwargs):
                return LaggedStart(a, *args, **kwargs)
    #         Animation Unwrite()
            def auw(a, *args, **kwargs):
                return Unwrite(a, *args, **kwargs)
    #         Animation FadeOut()
            def afo(a, *args, **kwargs):
                return FadeOut(a, *args, **kwargs)
    #         Animation FadeIn()
            def afi(a, *args, **kwargs):
                return FadeIn(a, *args, **kwargs)
    #         Animation FadeOut()
            def afoo(a, *args, **kwargs):
                return FadeOut(a, *args, shift=DOWN, **kwargs)
    #         Animation FadeIn()
            def afii(a, *args, **kwargs):
                return FadeIn(a, *args, shift=DOWN, **kwargs)
    #         Animation Restore()
            def are(a, *args, **kwargs):
                return Restore(a, *args, **kwargs)
    #         Animation Rotate()
            def aro(a, b, *args, **kwargs):
                return Rotate(a, about_point = b.get_center(), *args, **kwargs)
    #         Animation DrawBorderThenFill()
            def adb(a, *args, **kwargs):
                return DrawBorderThenFill(a, *args, **kwargs)
    #         Animation DrawBorderThenFill() reverse
            def adbr(a, *args, **kwargs):
                return DrawBorderThenFill(a, *args, **kwargs, reverse_rate_function = True)
    #         Animation GrowFromCenter()
            def agf(a, *args, **kwargs):
                return GrowFromCenter(a, *args, **kwargs)
    #         Animation MoveAlongPath()
            def ama(a, b, *args, **kwargs):
                return MoveAlongPath(a, b, *args, **kwargs)
#             Animation SpinInFromNothing
            def asi(a, *args, **kwargs):
                return SpinInFromNothing(a, angle=2 * PI, *args, **kwargs)
#             Animation SpinInFromNothing reverse
            def asir(a, *args, **kwargs):
                return SpinInFromNothing(a, angle=2 * PI, *args, **kwargs, reverse_rate_function = True)
#             Animation ShrinkToCenter
            def ast(a, *args, **kwargs):
                return ShrinkToCenter(a, *args, **kwargs)
#             Animation Circumscribe
            def ac(a, *args, **kwargs):
                return Circumscribe(a, *args, **kwargs)
#             Animation Indicate
            def ai(a, *args, **kwargs):
                return Indicate(a, *args, **kwargs)
#             Animation Restore
            def ar(a, *args, **kwargs):
                return Restore(a, *args, **kwargs)
        
#             Group sheen
            def gs(*args):
                li = []
                for i in args:
                    li.append(i.animate.set_sheen(0.1))
                return AnimationGroup(*li, run_time=0.5)
#             Group color
            def gc(*args):
                li = []
                for i in range(len(args)):
                    if i % 2 == 0:
                        li.append(args[i].animate.set_color(args[i+1]))
                return AnimationGroup(*li)
            
    #         mobject Text
            def mt(text, *args, **kwargs):
                return Text(text, *args, **kwargs)
    #         mobject SVGMobject
            def msm(name, *args, **kwargs):
                sm = SVGMobject(f'D:\\manimSVG\\{name}.svg')
                return sm
    #         mobject MathTex
            def mmt(text, *args, **kwargs):
                return MathTex(text, *args, **kwargs)
    #         mobject VGroup
            def mvg(*args, **kwargs):
                return VGroup(*args, **kwargs)
    #         mobject ArcBetweenPoints
            def mab(a, b, *args, **kwargs):
                return ArcBetweenPoints(a.get_center(), b.get_center(), angle = 120*DEGREES, *args, **kwargs)
#             mobject DashedLine
            def mdl(a, b, *args, **kwargs):
                return DashedLine(a, b, *args, **kwargs)
#         other function
        if type('other function') == str:
#             shift
            def sh(*args):
                i = 1
                for a in args:
                    if i % 2 != 0:
                        a.shift(args[i])
                    i += 1
#             scale
            def sc(*args):
                i = 1
                for a in args:
                    if i % 2 != 0:
                        a.scale(args[i])
                    i += 1 
#             coloring
            def c(*args):
                i = 1
                for a in args:
                    if i % 2 != 0:
                        xcss(a, args[i])
                    i += 1 
#             Wait
            def w(*args):
                return Wait(*args)
        
    #         refresh
            def refresh(*args, **kwargs):
                self.clear()
                sa(*args, **kwargs)
    #         color refresh
            def crefresh(*args, **kwargs):
                sc()
                for i in args:
                    xcoi(i)
                sa(*args, **kwargs)
#             execute narrator
            def ext(a):
                for i in a:
                    globals()[f't{str(i)}']=xn(a[i])
#             execute narrator 2
            def exn(a):
                for i in a:
                    globals()[f't{str(i)}']=xn2(a[i])
#             execute mobject
            def exm(name, num):
                for i in range(num):
                    globals()[name + str(i+1)]=msm(name + str(i+1))
#             ApplyMethod Shift
            def lsh(a, b):
                return ApplyMethod(a.shift,b)
#             ApplyMethod Scale
            def lsc(a, b):
                return ApplyMethod(a.scale,b)
#         temporary
        if type('temporary') == str:
            def dotflash(a):
                self.play(afi(a[0]))
                n = len(a)
                for i in range(n-1):
                    if i <= 5:
                        self.play(xal(0.5,afo(a[i]),afi(a[i+1])),run_time=1/(i+1))
                    elif i >= n-5:
                        self.play(xal(0.5,afo(a[i]),afi(a[i+1])),run_time=2/(n-i+1))
                    else:
                        self.play(xal(0.5,afo(a[i]),afi(a[i+1])),run_time=1/6)
            def orbitname(a,b):
                t1 = mmt(a).scale(1.2)
                t2 = mmt(b).scale(0.8).next_to(t1,d)
                vg = mvg(t1,t2)
                return vg
            def myan(a,b,c):
                r = (b-a)/c
                vg = mvg()
                for i in range(c):
                    vg.add(Annulus(inner_radius=a+i*r,outer_radius=a+(i+1)*r))
                return vg
View Code

scene

        def playscene1():
            title = Text('单电子原子结构', font='STZhongsong')
            ext({1:'1913年,丹麦物理学家 Bohr 提出了原子结构模型',2:'氢原子的电子沿着以原子核为中心的圆形轨道上运动',3:'符合要求的圆形轨道的半径是不连续的',4:'电子在轨道中跃迁时会相应地放出或吸收能量',
                5:'但是 Bohr 理论也有很大的局限性',6:'这只适用于单电子的类氢离子体系',7:'对于多电子原子,Bohr 理论忽略了电子间的相互作用',8:'更本质的原因是电子的运动并不遵循经典的力学定律',
                9:'实际上,电子在某一时刻的位置无法确定',10:'因此必须从电子的本性及其运动规律入手,建立新的理论'})
            nu = Circle(radius=0.3, color=BLUE_B, fill_opacity=1);el = Circle(radius=0.15, color=RED_B, fill_opacity=1).shift(0.8*r);orb1 = Circle(radius=0.8, color=BLUE_B);orb2 = Circle(radius=1.5, color=BLUE_B);orb3 = Circle(radius=2.8, color=BLUE_B)
            el2=Circle(radius=0.15, color=RED_B, fill_opacity=1);el3=el2.copy();sh(el2,1.5*d,el3,2.8*l)
            p1 = ImageMobject(r"C:\Users\86158\Music\p1.png").scale(0.3).shift(3.5*l+0.8*u);name=xn('Niels Henrik David Bohr').next_to(p1,DOWN);name2=xn('(1885-10-7—1962-11-18)').scale(0.8).next_to(name,DOWN);p11=Group(p1,name,name2)
            y1 = mmt(r'r=\frac{n^2h^2\varepsilon _0}{\pi me^2}').scale(1.2);y2 = mmt('(n=1,2,3…)').scale(0.9).next_to(y1,DOWN);y0=mvg(y1,y2).next_to(orb3,2*r).shift(2*u)
            cr = msm('cross').scale(1.5)
            c(nu,BLUE,el,RED,cr,GREEN)
            z1 = mvg(xdg(1,0.8,0.8),xdg(1,1.5,1.5),xdg(1,2.8,2.8));z2 = xdg(30,0.8,2.8);l1=mdl(z1[0],z1[1]);l2=mdl(z1[1],z1[2]);l3=mdl(z1[2],z1[0]);
            nu.save_state();el.save_state();sc(nu,3.5,el,1.5);sh(nu,3*r+0.6*d);el.next_to(nu,3*u);x2=xn('+e').scale(1.5).move_to(nu);x3=xn('Z=1').next_to(nu,d);x1=xn('-e').scale(1.5).next_to(el,UP);
            
            xxp(adb(title),afo(title),[afi(t1),afii(p11)],[agf(nu),agf(el)],xal(0.3,afii(x1),afii(x2),afii(x3)),[at(t1,t2),afo(p11),afo(x1),afo(x2),afo(x3),ar(nu),ar(el)],xal(0.5,agf(orb1),agf(orb2),agf(orb3)))
            xxp(ama(el,orb1,run_time=2),at(t1,t3),aw(y0),xal(0.5,ai(orb1,color=PINK),ai(orb2,color=PINK),ai(orb3,color=PINK)),afo(y0),at(t1,t4),xmaa(el,el,el3,1),xmaa(el,el3,el2,1),at(t1,t5),w(0.5),at(t1,t6),w(0.5),at(t1,t7),w(0.5),at(el,z1),xal(0.3,agf(l1),agf(l2),agf(l3)))
            xxp(at(t1,t8),w(0.5),xal(0.3,ast(l3),ast(l2),ast(l1),ast(orb1),ast(orb2),ast(orb3)),xal(0.5,aro(el[0],nu,angle=2*PI,run_time=2),aro(el[1],nu,angle=2*PI,run_time=2),aro(el[2],nu,angle=2*PI,run_time=2)),at(t1,t9),w(0.5),afo(el));dotflash(z2);xxp(at(t1,t10),w(),afo(t1,z2[-1],nu))
        def playscene2():
            p2=ImageMobject(r"C:\Users\86158\Music\p2.png");f1=mmt(r'\left [ -\frac{h^2}{8\pi ^2m} \nabla ^2 + V \right ] \psi =E\psi');f2=mmt(r'\psi (x,y,z)');f3=mmt(r'\psi (r,\theta ,\phi )');f4=mmt(r'\psi (r,\theta ,\phi ) = R(r)\cdot \Theta (\theta )\cdot\Phi (\phi )')
            f5=mmt(r'\frac{\sin^2 \theta }{R} \frac{d}{dr} \left ( r^2\frac{dR}{dr}  \right ) + \frac{8\pi ^2\mu r^2\sin^2 \theta}{h^2}\left ( E+\frac{Ze^2}{4\pi\varepsilon _0r}  \right ) +\frac{\sin \theta}{\Theta }\frac{d}{d\theta} \left (\sin \theta  \frac{d\Theta}{d\theta}\right )','+', r'\frac{1}{\Phi } \frac{d^2\Phi}{d\phi ^2}','=0   ')
            f6=mmt(r'\frac{1}{\Phi } \frac{d^2\Phi}{d\phi ^2}','=-m^2');f7=mmt(r'\frac{1}{R} \frac{d}{dr} \left ( r^2\frac{dR}{dr}  \right ) + \frac{8\pi ^2\mu r^2}{h^2}\left ( E+\frac{Ze^2}{4\pi\varepsilon _0r}  \right )',' +',r'\frac{1}{\Theta \sin \theta}\frac{d}{d\theta} \left (\sin \theta  \frac{d\Theta}{d\theta}\right )-\frac{m^2}{\sin^2 \theta} ','=0')   
            f8=mmt(r'\frac{1}{R} \frac{d}{dr} \left ( r^2\frac{dR}{dr}  \right ) + \frac{8\pi ^2\mu r^2}{h^2}\left ( E+\frac{Ze^2}{4\pi\varepsilon _0r}  \right )',r'=\beta ')
            f9=mmt(r'\frac{1}{\Theta \sin \theta}\frac{d}{d\theta} \left (\sin \theta  \frac{d\Theta}{d\theta}\right )-\frac{m^2}{\sin^2 \theta} ',r'=-\beta')
            v1=mmt(r'\Phi',r' =\left ( \frac{1}{\sqrt{2\pi } }  \right ) e^{im\phi }');
            v2=mmt(r'\Theta',r' =\left ( -1 \right ) ^m\left [ \frac{(2l+1)}{2}\frac{(l-\lvert m \rvert)!}{(l+\lvert m \rvert)!}   \right ] ^{\frac{1}{2} }P^{\lvert m \rvert}_l(\cos \theta )')
            v3=mmt(r'R',r'=-\left [ (\frac{2Z}{na_0} ) ^3\frac{(n-l-1)!}{2n\left [ (n+l)! \right ]^3 } \right ] ^{\frac{1}{2} }e^{-\frac{\rho }{2} }\rho^lL^{2l+1}_{n+l}(\rho)')
            z1=mmt(r'\Phi _m');z2=mmt(r'\Theta _{l,m}');z3=mmt(r'R_{n,l}')
            sc(p2,1.6,f2,1.3,f3,1.3,f4,1.3,f5,0.7,z1,1.5,z2,1.5,z3,1.5,f7,0.8);sh(p2,3.5*l+u,f1,2.6*r,f2,3.5*r,f3,3.5*r,f6,2*u,f8,2*d,v1,2*u,v3,2*d,z1,4*l,z3,4*r)
            f00=mmt('-m^2').scale(0.7).move_to(f5[2])
            name=xn('Erwin Schrödinger').next_to(p2,DOWN);name2=xn('(1887-8-12—1961-1-4)').scale(0.8).next_to(name,DOWN);pic=Group(p2,name,name2)
            c1=msm('coord1').scale(3);c2=msm('coord2').scale(3);sh(c1,3*l+0.3*u,c2,3*l+0.3*u)
            
            ext({1:'1926年,奥地利物理学家 Schrödinger 提出用波动力学来描述电子的运动',2:'对于氢原子,采用球坐标系更容易求解',3:'随后采取变数分离法,设ψ为三个一元函数的乘积',4:'代入 Schrödinger 方程并化简',
                5:'固定r和θ,改变φ,原式恒成立',6:'这说明含φ的式子为常数,为了后续计算方便,设为-m²',7:'化简后同理可知,含r和θ的式子也为常数,设为β',8:'在解函数的过程中发现,β只有等于l(l+1),且l为自然数时函数才有意义',9:'三个方程解的形式为:',
                10:'这就产生了三个量子数n,l,m',11:'也就是说,一组n,l,m决定一个波函数ψ'})
            
            
            xxp([afii(pic),afi(t1),afii(f1)],w(),[afo(pic),at0(t1,t2),f1.animate.to_edge(UP)],afii(c1),afii(f2));xxp([xt2(c1,c2,[3,9,2,10,5,7,4,5,6,6]),agf(c2[3]),agf(c2[4]),agf(c2[2])],at(f2,f3));refresh(t1,f1,c2,f3)
            xxp(afoo(c2),[f3.animate.move_to(ORIGIN),f1.animate.move_to([0,2,0])],at0(t1,t3),at(f3,f4),at0(t1,t4),at(mvg(f1,f4),f5),at0(t1,t5));refresh(t1,f5);sp(f5[2].animate.set_color(BLUE),run_time=2)
            xxp(at0(t1,t6),w(),[at(f5[2].copy(),f6[0]),afi(f6[1])],at0(f5[1:3],f00),at0(t1,t7),at(f5,f7));refresh(t1,f6,f7);sp(f7[0].animate.set_color(GOLD),f7[2].animate.set_color(GREEN),run_time=2)
            xxp([at(f7[0],f8[0]),at(f7[2],f9[0]),afo(f7[1],f7[3])],afi(f8[1],f9[1]));refresh(t1,f6,f8,f9);xxp(at0(t1,t8),w(1.5),at0(t1,t9),xal(0.3,afoo(f6),afii(v1),afoo(f9),afii(v2),afoo(f8),afii(v3)))
            xxp(at0(t1,t10),w(0.5),at0(t1,t11),[at(v1[0],z1),at(v2[0],z2),at(v3[0],z3),afo(v1[1],v2[1],v3[1])])
        def playscene3():
#             config.disable_caching=True
            z1=mmt(r'\Phi _m');z2=mmt(r'\Theta _{l,m}');z3=mmt(r'R_{n,l}');z4=mmt(r'Y_{l,m}')
            sc(z1,1.5,z2,1.5,z3,1.5,z4,1.5);sh(z1,4*l,z3,4*r,z4,2*l)
            p0=ImageMobject(r"C:\Users\86158\Music\0.png");p1=ImageMobject(r"C:\Users\86158\Music\1.png");p2=ImageMobject(r"C:\Users\86158\Music\2.png");p3=ImageMobject(r"C:\Users\86158\Music\3.png")
            ext({1:'也就是说,一组n,l,m决定一个波函数ψ',2:'Θ与Φ的乘积称为球谐函数,它决定了电子波函数的角度特性',3:'我们常常利用球谐函数来作图'})
            s=orbitname('s','(l=0,m=0)');px=orbitname('p_x','(l=1,m=1)');py=orbitname('p_y','(l=1,m=-1)');pz=orbitname('p_z','(l=1,m=0)');
            dz2=orbitname('d_{z^2}','(l=2,m=0)');dxz=orbitname('d_{xz}','(l=2,m=1)');dyz=orbitname('d_{yz}','(l=2,m=-1)');dx2y2=orbitname('d_{x^2-y^2}','(l=2,m=2)');dxy=orbitname('d_{xy}','(l=2,m=-2)');
            f1=orbitname('f_{z^3}','(l=3,m=0)').scale(0.8);f2=orbitname('f_{xz^2}','(l=3,m=1)').scale(0.8);f3=orbitname('f_{yz^2}','(l=3,m=-1)').scale(0.8);f4=orbitname('f_{xyz}','(l=3,m=2)').scale(0.8);f5=orbitname('f_{z(x^2-y^2)}','(l=3,m=-2)').scale(0.8);f6=orbitname('f_{x(x^2-3y^2)}','(l=3,m=3)').scale(0.8);f7=orbitname('f_{y(3x^2-y^2)}','(l=3,m=-3)').scale(0.8);                              
            sc(dz2,0.8,dxz,0.8,dyz,0.8,dx2y2,0.8,dxy,0.8)
            sh(s,2.5*d,px,2.5*d+4.5*r,py,2.5*d+4.5*l,pz,2.5*d,dz2,0.3*u+4.2*r+0.5*u,dx2y2,3*d+0.2*u,dyz,0.3*u+0.5*u,dxz,3*d+3.8*l+0.2*u,dxy,0.3*u+3.8*l+0.5*u,p2,0.3*u)
            sh(p3,0.3*u,f1,4.6*r+0.8*u,f2,2.9*d+4.2*l,f3,1.8*r+0.8*u,f4,1.3*l+0.8*u,f5,2.9*d+1.3*l,f6,4.2*l+0.8*u,f7,1.8*r+2.9*d)
            
            sa(z1,z2,z3,t1);xxp(at(t1,t2),w(0.5),[at(mvg(z1,z2),z4),z3.animate.shift(2*l)],at(t2,t3),w(0.5),afo(t3,z4,z3))
            xxp(afii(p0),afii(s),[afoo(p0),afoo(s)],afii(p1),xal(0.3,afii(py),afii(pz),afii(px)),w(),[afoo(p1),afoo(py),afoo(pz),afoo(px)],afii(p2),xal(0.3,afii(dxy),afii(dyz),afii(dz2),afii(dxz),afii(dx2y2)),w(2))
            xxp([afoo(p2),afoo(dxy),afoo(dyz),afoo(dz2),afoo(dxz),afoo(dx2y2)],afii(p3),xal(0.3,afii(f6),afii(f4),afii(f3),afii(f1),afii(f2),afii(f5),afii(f7)),w(2),[afoo(p3),afoo(f6),afoo(f4),afoo(f3),afoo(f1),afoo(f2),afoo(f5),afoo(f7)])
        def playscene4():
            pic=ImageMobject(r"C:\Users\86158\Music\xxx.png");pp=ImageMobject(r"C:\Users\86158\Music\1part.png");ss=ImageMobject(r"C:\Users\86158\Music\0part.png").scale(0.8);
            sss=ss.copy().scale(1.5);sh(ss,3.5*l+u,sss,3.5*r+u)
            s=orbitname('s','(l=0,m=0)');p=orbitname('p_z','(l=1,m=0)');d=orbitname('d_{z^2}','(l=2,m=0)');f=orbitname('f_{z^3}','(l=3,m=0)')
            px=orbitname('p_x','(l=1,m=1)');py=orbitname('p_y','(l=1,m=-1)');pz=orbitname('p_z','(l=1,m=0)');
            o1=orbitname('1s','(n=1,l=0,m=0)');o2=orbitname('2s','(n=2,l=0,m=0)');
            sh(pic,u,f,1.2*DOWN+4.7*r,s,1.2*DOWN+4.2*l,p,1.2*DOWN+1.3*l,d,1.2*DOWN+1.8*r,px,2.5*DOWN+4.5*r,py,2.5*DOWN+4.5*l,pz,2.5*DOWN)
            sh(o1,3.6*l+1.7*DOWN,o2,3.6*r+1.7*DOWN)
            ext({1:'l为角量子数,决定原子轨道的形状',2:'m为磁量子数,决定原子轨道在空间的取向',3:'n为主量子数,决定轨道的能量,也大体上决定轨道的大小'})
            sh(pp,1.2*u,px,1.2*u,py,1.2*u,pz,1.2*u)
            xxp([afii(pic),afi(t1)],xal(0.3,afii(s),afii(p),afii(d),afii(f)),w(),[at(t1,t2),afoo(pic,s,p,d,f)],afii(pp),xal(0.3,afii(py),afii(pz),afii(px)),w())
            xxp([at(t2,t3),afoo(pp,px,py,pz)],[afii(ss),afii(sss)],xal(0.3,afii(o1),afii(o2)),w(),[afoo(ss,sss,o1,o2),afo(t3)])
        def playscene5():
            z1=mmt(r'R_{n,l}');z2=mmt(r'Y_{l,m}')
            sc(z1,1.5,z2,1.5);sh(z1,2*r,z2,2*l)
            n1=mmt(r'a_0^{3/2}R');n2=mmt(r'r/a_0')
            ext({1:'R为径向函数,它决定了电子波函数的径向特性',2:'例如,2s轨道截面的电子几率密度如图所示',3:'实际上电子出现的几率密度由|ψ²|决定',4:'|ψ²|在空间的分布称为电子云'})
            graph=msm('graph');c1=myan(0,0.7,15);c2=myan(0.7,2.7,30)
            d1=xdg(100,0,0.4);d2=xdg(100,0.4,0.6);d3=xdg(300,0.8,2);d4=xdg(100,2,2.7)
            sc(graph,2.5,n1,0.8,n2,0.8);sh(graph,1.55*r+0.35*u,n1,0.7*l+2.6*u,n2,0.5*d+2.8*r)
            
            
            xxp(afi(z1,z2,t1),w(),[afo(z1,z2),at(t1,t2)],[adb(c1),adb(c2)],[c1.animate.set_color_by_gradient(BLUE,BLACK),c2.animate.set_color_by_gradient(BLACK,BLUE,BLACK)])
            xxp(Write(graph[1:9]),[Write(n1),Write(n2)],Write(graph[0],run_time=2),at(t2,t3),afo(graph,n1,n2),at(t3,t4),[at(c1,mvg(d1,d2)),at(c2,mvg(d3,d4))],w(),afo(t4,d1,d2,d3,d4))
        def playscene0():
            title = mt('本期视频BGM及推荐者',font='YouYuan').scale(0.8).to_edge(UP)
            m1 = ImageMobject(r"C:\Users\86158\Downloads\111.png").scale(2);n1=xn('孟欣不会画画').set_color_by_gradient(['#FFE4B5','#F5FFFA']).scale(1.1).next_to(m1);v1=Group(m1,n1);xpp(v1,'r')
            t1 = mt('Undertale',font='STFangsong').scale(0.6).scale(1.3);xpp(t1,'l')
            sw(0.5);sp(adb(title));sp(agf(m1));sp(agf(n1));sp(afi(t1));sw(2);sp(afo(title,v1,t1));sw(0.5)
View Code

 

标签:xxp,return,color,args,electron,Single,structure,kwargs,def
From: https://www.cnblogs.com/daxiangcai/p/16723854.html

相关文章