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

Multi electron atomic structure

时间:2022-09-28 20:15:32浏览次数:112  
标签:Multi set return color args electron 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
#         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.1, 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)
#             Animation Shift
            def ash(a, b, *args, **kwargs):
                return ApplyMethod(a.shift, b, *args, **kwargs)
#             Animation Succession
            def asu(*args):
                return Succession(*args)
#             Animation moveto
            def amt(a, b, *args, **kwargs):
                return ApplyMethod(a.move_to, b, *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 movearound(a,b,t):
                li = []
                center = b
                for i in range(t):
                    x = np.random.rand()*0.3
                    y = np.random.rand()*2*PI
                    li.append(amt(a,center+x*np.cos(y)*r+x*np.sin(y)*u,run_time=0.5,rate_func=rate_functions.smooth))
                return asu(*li)
            def movearound2(a,t):
                li = []
                center = a.get_center()
                for i in range(t):
                    x = np.random.rand()*0.3
                    y = np.random.rand()*2*PI
                    li.append(amt(a,center+x*np.cos(y)*r+x*np.sin(y)*u,run_time=0.5,rate_func=rate_functions.smooth))
                return asu(*li)
            def autograph(a,b,c):
                pic=ImageMobject(a).scale(1.3).shift(3.5*l+0.8*u)
                name=xn(b).next_to(pic,DOWN);name2=xn(c).scale(0.8).next_to(name,DOWN)
                return Group(pic,name,name2)
            def bounce(a):
                return afi(a,shift=3*d,rate_func=rate_functions.ease_out_bounce,run_time=2)
            def setz(z,*args):
                for i in args:
                    i.set_z_index(z)
            def vmove(a,b):
                li=[];c=a.get_center()
                li.append(ash(a,(b[1]-c[1])*u))
                li.append(ash(a,(b[0]-c[0])*r))
                return asu(*li)
            def mylist(a,b):
                li=[];li2=[]
                for i in a:
                    li.append(xn(i).scale(1.5))
                for i in range(len(li)):
                    if i !=0:
                        li[i].next_to(li[i-1],2.8*r)
                        li[i].set_y(li[0].get_y())
                for i in range(len(li)):
                    li2.append(xn(b[i]).scale(1.2).next_to(li[i],3*d))
                for i in range(len(li2)):
                    if i !=0:
                        li2[i].set_y(li2[0].get_y())
                vg1=mvg(*li);vg2=mvg(*li2)
                return mvg(vg1,vg2).move_to(ORIGIN)
View Code

scene 1~5

        def playscene1():
            title=Text('多电子原子结构', font='STZhongsong')
            ext({1:'多电子原子的 Schrödinger 方程更加复杂',2:'以氦原子为例,需要考虑三种静电相互作用',3:'核对两个电子的吸引力以及两个电子间的排斥力',4:'由于存在电子间的排斥作用,多电子的 Schrödinger 方程无法变数分离',5:'所以没有解析解'})
            nu=Circle(radius=0.5, fill_opacity=1).set_color_by_gradient([BLUE,PURPLE]);e1=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);e2=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED])             
            sh(e1,1.8*r+2.3*u,e2,2.8*r+0.4*u)
            i1=mdl(nu,e1);i2=mdl(nu,e2);i3=mdl(e1,e2);la1=mmt(r'\hat{H} =',r'-\frac{\hbar ^2}{2m_e} \nabla _1^2-\frac{2e^2}{4\pi \varepsilon _0r_1}',r'-\frac{\hbar ^2}{2m_e} \nabla _2^2-\frac{2e^2}{4\pi \varepsilon _0r_2}',r'+\frac{e^2}{4\pi \varepsilon _0r_{12}}')
            la2=mmt(r'\hat{H}\psi =E\psi');
            sc(la1,0.8,la2,0.8);sh(la1,0.5*d,la2,2*d)
            c(i1,BLUE,i2,PURPLE,i3,GOLD,la1[1],BLUE,la1[2],PURPLE,la1[3],GOLD)
            vg1=mvg(nu,e1,e2,i1,i2,i3);nu.save_state();e1.save_state();e2.save_state();
            
            
            xxp(adb(title),afo(title),afi(t1),w(0.5),at(t1,t2),xal(0.3,agf(nu),agf(e1),agf(e2)),at(t2,t3),xal(0.3,agf(i1),agf(i2),agf(i3)),[vg1.animate.scale(0.8).shift(u),afi(la1,la2,shift=UP)],at(t3,t4),w(),at(t4,t5),[afo(t5,i1,i2,i3),afoo(la1,la2),ar(nu),ar(e1),ar(e2)])
        def playscene2():
            ext({1:'氦原子的电子构型为1s²',2:'如果体系中存在三个电子,电子构型是否为1s³呢?',3:'事实并非如此,因为电子的排布需要满足 Pauli 不相容原理',4:'在同一轨道中的电子具有相同的n,l,m',5:'但自旋量子数只有两个取值:+1/2和-1/2',6:'因此 Pauli 不相容原理也可以表述为:',7:'在一个原子轨道中最多容纳两个自旋方向相反的电子',
                8:'因此,锂原子的前两个电子会填充到1s上',9:'那么第三个电子会填充到2s上还是2p上呢?'})
            nu=Circle(radius=0.5, fill_opacity=1).set_color_by_gradient([BLUE,PURPLE]);e1=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);e2=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);e3=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);
            sh(e1,1.8*r+2.3*u,e2,2.8*r+0.4*u);e3.move_to([1.126,-0.65,0])
            s = ImageMobject(r"C:\Users\86158\Music\s.png").set_z_index(2);e3.set_z_index(-1).set_opacity(0)
            p = ImageMobject(r"C:\Users\86158\Music\pz.png");
            r1=xn2('在原子中不允许存在');r2=xn2('四个量子数完全相同的两个电子');r3=xn('Pauli 不相容原理').scale(1.3)
            sh(s,0.25*l,r1,2.5*r+3*u);r2.next_to(r1,d);r3.next_to(r1,5*u);pauli=autograph(r"C:\Users\86158\Music\Pauli.png",'Wolfgang Pauli','1900-4-25—1958-12-15')
            adg1=xdg(8,0,1.8).set_z_index(-2)
            s2=s.copy();sc(s2,1.4,p,1.2);sh(s2,0.1*l,p,0.28*l)
            
            sa(nu,e1,e2);xxp([afi(t1),amt(e1,[0,1.3,0]),amt(e2,[-1.126,-0.65,0])]);sp(movearound(e1,[0,1.3,0],10),movearound(e2,[-1.126,-0.65,0],10),asu(agf(s),at(t1,t2),e3.animate.set_opacity(1),movearound(e3,[1.126,-0.65,0],4)));xxp(at(t2,t3),afo(nu,e1,e2,e3,s))
            xxp([afii(pauli),afii(r1,r2,r3)],w(),[afoo(pauli,r1,r2,r3),afii(adg1,s),at(t3,t4)],w(),at(t4,t5),w(),ast(adg1[2:]),at(t5,t6),w(0.5),at(t6,t7),w(),at(t7,t8),w(0.5),at(t8,t9),afii(s2),afii(p),[ast(s),ast(adg1[0:2]),afo(t9)],[ash(s2,3*l),ash(p,3*r)])
        def playscene3():
            ext({1:'与氢原子不同,多电子原子中2s与2p轨道的能量不一致',2:'这与屏蔽效应和钻穿效应有关',3:'在原子中,外层电子会受到内层电子的排斥作用',4:'这种作用削弱了核电荷对该电子的吸引作用',5:'即有效核电荷降低了,这就是屏蔽效应',
                6:'2s轨道和2p轨道上的电子都会受到1s轨道上的电子的排斥作用',7:'但是2s轨道上的电子受到的排斥更小',8:'这是因为2s在壳层概率分布上比2p多了一个离核较近的峰',9:'2s钻得离核更近,能更多地避免其余电子的屏蔽',10:'这就是钻穿效应'})
            s = ImageMobject(r"C:\Users\86158\Music\s.png").set_z_index(-1).shift(0.25*l);
            s0 = ImageMobject(r"C:\Users\86158\Music\s.png").set_z_index(-1).scale(0.6)
            p = ImageMobject(r"C:\Users\86158\Music\pz.png").set_z_index(-1);
            sc(s,1.4,p,1.2);sh(s,0.1*l+3*l,p,0.28*l+3*r)
            nu=Circle(radius=0.5, fill_opacity=1).set_color_by_gradient([BLUE,PURPLE]);e1=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);e2=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);e3=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);
            sh(e1,1.8*r+2*u);e2.move_to([1.2,0.3,0]);e3.move_to([0.7,1,0])
            chart=msm('chart').scale(2);note1=mmt(r'4\pi r^2R(r)^2');xcoi(chart);note2=mmt('r');note3=mmt('2s');note4=mmt('2p');c(note3,bb,note4,rr)
            s01=s0.copy();s02=s0.copy();
            sh(note1,4*l+1.7*u,note2,5*r+2.3*d,note3,0.5*u+2*l,note4,3*l+0.5*u,s01,3.2*l,s02,2.8*r)

            sa(s,p);xxp(afi(t1),at(t1,t2),[afoo(s,p),afii(nu,e1,e2,e3)],at(t2,t3),(ash(e1,0.6*u+0.6*r),ash(e1,0.6*d+0.6*l)),[ast(e2),ast(e3),at(t3,t4)],w(),at(t4,t5),w(0.5))
            xxp([at(t5,t6),ast(nu),ast(e1),afii(s,p)],[s.animate.scale(0.8),p.animate.scale(0.8),agf(s01),agf(s02)],at(t6,t7),w(0.5),[at(t7,t8),aw(chart[0:4])],[aw(note1),aw(note2)],[aw(chart[4]),aw(chart[5])],[aw(note3),aw(note4)],at(t8,t9),[afo(note3,note4),chart[4:6].animate.scale(3).shift(1.7*u+9.65*r)],w(),at(t9,t10),afo(t10,chart,note1,note2,s,p,s01,s02))
        def playscene4():
            ext({1:'因此锂原子的第三个电子会填充到能量更低的2s轨道上',2:'同理可知,在同一电子层中,能量按照s、p、d、f的次序增高',3:'如果再增加一个电子,会继续填充到2s轨道上',4:'再增加一个电子,则开始填充到2p轨道上',5:'如果再增加一个电子呢?',6:'它会填充到原来的2p轨道还是新的2p轨道呢?',7:'电子会填充到新的2p轨道,因为这样电子间的排斥力会更小',
                8:'这就是 Hund 规则'})
            s = ImageMobject(r"C:\Users\86158\Music\s.png").set_z_index(2)
            e1=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);e2=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);e3=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]);
            s2=s.copy().set_z_index(2);sc(s2,1.4);sh(s2,0.1*l)
            p = ImageMobject(r"C:\Users\86158\Music\pz.png").set_z_index(2).scale(1.2);
            p2 = ImageMobject(r"C:\Users\86158\Music\px.png").set_z_index(3).scale(0.9);
            
            sh(e1,0.7*l+0.3*d,e2,0.8*r+0.4*u,e3,4*r);e4=e3.copy();e5=e4.copy();e6=e5.copy()
            
            xxp([afi(t1),afii(s,s2,e1,e2,e3)],amt(e3,[1.8,-1.8,0]),at(t1,t2),w(),at(t2,t3),agf(e4),amt(e4,[2.2,1.5,0]),w(0.5),[at(t3,t4),afoo(s,s2,e1,e2,e3,e4),afii(p)],agf(e5),amt(e5,[0.3,2,0]),at(t4,t5),agf(e6),at(t5,t6),afii(p2),at(t6,t7),amt(e6,[2.3,0.7,0]),[at(t7,t8),afoo(p,p2,e5,e6)])
        def playscene5():
            ext({1:'这就是 Hund 规则',2:'因此,再增加一个电子,它会以自旋相同的方式占据新的2p轨道'})
            hund=autograph(r"C:\Users\86158\Music\hund.png",'Friedrich Hund','1896-2-4—1997-3-31')
            r1=xn2('电子分布到能量简并的原子轨道时').scale(0.8);r2=xn2('优先以自旋相同的方式分别占据不同的轨道').scale(0.8);r3=xn('Hund 规则').scale(1.3);rule=mvg(r1,r2,r3)
            sh(r1,2.5*r+3*u);r2.next_to(r1,d);r3.next_to(r1,5*u);
            p = ImageMobject(r"C:\Users\86158\Music\pz.png").set_z_index(2).scale(1.2);
            p2 = ImageMobject(r"C:\Users\86158\Music\px.png").set_z_index(3).scale(0.9);
            p3 = ImageMobject(r"C:\Users\86158\Music\py.png").set_z_index(4).scale(0.9);
            e1=Circle(radius=0.15, fill_opacity=1).set_color_by_gradient([PURPLE,RED]).move_to([0.3,2,0]);e2=e1.copy().move_to([2.3,0.7,0]);e3=e1.copy().move_to([4,0,0])
            
            sa(t1);xxp(afii(hund,rule),w(1.5),[at(t1,t2),afoo(hund,rule)],afii(e1,e2,p,p2),agf(e3),afii(p3),amt(e3,[1.8,-0.7,0]),afoo(t2,p,p2,p3,e1,e2,e3))
View Code

scene 6~

        def playscene6():
            ext({1:'up主楼上工具人举了一个很形象的例子来理解核外电子的排布',2:'原子就像一座食堂,桌子代表原子轨道',3:'同学在座位上就餐代表电子填充进原子轨道',4:'在食堂就餐时一般不愿意多爬楼',5:'这就是能量最低原理:电子优先填充能量低的轨道',
                6:'一张桌子只能坐两个人,且两人的朝向相反',7:'这就是 Pauli 不相容原理:一个原子轨道只能容纳两个自旋相反的电子',8:'如果有多张桌子可供选择,陌生人一般会刻意避免坐同一张桌子',9:'这就是 Hund 规则:在能量相等的轨道上,电子优先自旋平行地占据不同的轨道'})
            f1=msm('f1').scale(0.7);f2=msm('f2').scale(0.7);f3=f2.copy();sh(f1,1.8*d,f3,1.8*u);fall=mvg(f1,f2,f3);l1=xn('1s').move_to(f1[1]);l2=xn('2s').move_to(f2[1]);l3=xn('2p').move_to(f2[8]);l4=xn('3s').move_to(f3[1]);l5=xn('3p').move_to(f3[8]);lall=mvg(l1,l2,l3,l4,l5).set_z_index(10);c(lall,bb)
            sh(lall,0.1*u);
            haha=ImageMobject(r"C:\Users\86158\Music\haha.png");name=xn('楼上工具人').scale(1.6).next_to(haha,DOWN);person=Group(haha,name).move_to(ORIGIN)
            p1=msm('p1').scale(0.6).shift(1.8*d+5.8*l);p2=msm('p2').scale(0.6).shift(1.8*d+5.8*l);setz(2,f1[0],f2[0],f2[2:7]);setz(3,p1);setz(4,f1[1],f2[1],f2[7:10]);setz(5,p2)
            p3=p1.copy();p4=p2.copy();p5=p1.copy();p6=p1.copy();p7=p1.copy();p8=p2.copy()
            xxp([agf(haha),adb(name),afi(t1)],w(0.5))
            xxp([at(t1,t2),afoo(person),afii(f1[0],f2[0],f2[2:7],f3[0],f3[2:7])],xal(0.1,bounce(f1[1]),bounce(f2[7]),bounce(f2[1]),bounce(f2[9]),bounce(f2[8]),bounce(f3[9]),bounce(f3[7]),bounce(f3[1]),bounce(f3[8])),xal(0.3,agf(l1),agf(l2),agf(l3),agf(l4),agf(l5)))
            xxp([at(t2,t3),agf(p1)],[afo(lall),afo(f3,shift=UP),f1.animate.scale(1.7).move_to([0,-1.3,0]),f2.animate.scale(1.7).move_to([0,1.7,0])],w(0.5))
            pos1=f1[1].get_center()+0.7*u;pos2=f1[1].get_center()+0.1*d;pos5=f2[7].get_center()+0.9*u;xxp(at(t3,t4),vmove(p1,pos1),at(t4,t5),w(0.5),at(t5,t6),agf(p2),vmove(p2,pos2),at(t6,t7),w(1.5),[afo(t7),agf(p3)])
            pos3=f2[1].get_center()+0.7*u;pos4=f2[1].get_center()+0.1*d;pos6=f2[8].get_center()+0.9*u;pos7=f2[9].get_center()+0.9*u;pos8=f2[7].get_center()+0.4*d;
            xxp(vmove(p3,pos3),agf(p4),vmove(p4,pos4),agf(p5),vmove(p5,pos5),agf(p6),afi(t8),w(),vmove(p6,pos6),at(t8,t9),w(1.5),[afo(t9),agf(p7)],vmove(p7,pos7),agf(p8),vmove(p8,pos8),afo(f1,f2,p1,p2,p3,p4,p5,p6,p7,p8));
        def playscene7():
            ext({1:'需要注意的是,由于屏蔽效应和钻穿效应的影响',2:'原子轨道的能量不仅与n有关,也与l有关',3:'我国化学家徐光宪教授提出了一个定量的近似规则',4:'原子轨道的n+0.7l值越大,能级越高',5:'因此会产生能级交错现象,例如4s轨道的能量低于3d轨道',6:'因此填充电子时4s轨道优先于3d轨道',
                7:'另外,电子填充时也有某些特殊情况',8:'例如,能量相等的轨道全充满、半满或全空的状态比较稳定',9:'称为 Hund 第二规则,典型的例子是 Cr 和 Cu',10:'此时并没有先填满4s轨道再填充3d轨道',11:'因为半满或全满的3d轨道能量更低'})
            q1=mylist(['1s','2s','2p','3s','3p','3d','4s','4p','4d','4f'],['1','2','2.7','3','3.7','4.4','4','4.7','5.4','6.1'])
            xu=autograph(r"C:\Users\86158\Music\xu.png",'徐光宪','1920-11-7—2015-4-28');text=xn('n + 0.7l').scale(2).move_to([3,0,0])
            p1=mmt('Cr').scale(1.3);p2=mmt('Cu').scale(1.3);p3=mmt('[Ar]3d^54s^1').scale(1.3);p4=mmt('[Ar]3d^{10}4s^1').scale(1.3);p5=mmt('[Ar]3d^44s^2').scale(1.3);p6=mmt('[Ar]3d^94s^2').scale(1.3);psay=xn2('而不是:').scale(1.2).move_to(ORIGIN)   
            sh(p3,2.6*l,p4,2.6*r,p5,2.6*l+1.5*d,p6,2.6*r+1.5*d,psay,5.5*l+1.5*d,p1,2.6*l+1.5*u,p2,2.6*r+1.5*u);c(p5,bb,p6,bb,psay,bb)
            xxp(afi(t1),afii(q1[0]),at(t1,t2),w(0.5),[at(t2,t3),afoo(q1[0]),afii(xu,text)],w(0),at(t3,t4),w(0),[afoo(xu,text),afii(q1[0])],afii(q1[1]),at(t4,t5),w(0),[Swap(q1[0][5],q1[0][6]),Swap(q1[1][5],q1[1][6])],at(t5,t6),afoo(q1))
            xxp(at(t6,t7),w(0.5),at(t7,t8),w(1.5),[at(t8,t9),afii(p1,p2,p3,p4)],w(),at(t9,t10),afii(p5,p6,psay),w(),at(t10,t11),w(0),[afoo(p1,p2,p3,p4,p5,p6,psay),afo(t11)])
        def playscene0():
            title = mt('本期视频BGM及推荐者',font='YouYuan').scale(0.8).to_edge(UP)
            m1 = ImageMobject(r'C:\Users\86158\Music\qq1.png').scale(2);n1=xn('nian_fa').set_color(color=['#FFE4E1','#FFC1C1']).scale(1.1).next_to(m1);v1=Group(m1,n1);xpp(v1,'ur')
            m2 = ImageMobject(r'C:\Users\86158\Music\qq2.png').scale(2);n2=xn('Slimer-').set_color(color=['#EE6363','#FFD39B']).scale(1.1).next_to(m2);v2=Group(m2,n2);xpp(v2,'dr')
            t1 = mt('同じ高みへ',font='STFangsong').scale(0.6).scale(1.3);xpp(t1,'ul')
            t2 = mt('星茶会',font='STFangsong').scale(0.6).scale(1.3);xpp(t2,'dl')
            sw(0.5);sp(adb(title));sp(xal(0.3,agf(m1),agf(m2)));sp(xal(0.3,agf(n1),agf(n2)));sp(afi(t1,t2));sw(2);sp(afo(title,v1,v2,t1,t2));sw(0.5)
View Code

 

标签:Multi,set,return,color,args,electron,structure,kwargs,def
From: https://www.cnblogs.com/daxiangcai/p/16739399.html

相关文章