Exemplo n.º 1
0
    def __init__(self, mobject1, mobject2, 
                 run_time = DEFAULT_TRANSFORM_RUN_TIME,
                 interpolation_function = straight_path,
                 black_out_extra_points = False,
                 *args, **kwargs):
        self.interpolation_function = interpolation_function
        count1, count2 = mobject1.get_num_points(), mobject2.get_num_points()
        if count2 == 0:
            mobject2 = Point((SPACE_WIDTH, SPACE_HEIGHT, 0))
            count2 = mobject2.get_num_points()
        Mobject.align_data(mobject1, mobject2)
        Animation.__init__(self, mobject1, run_time = run_time, *args, **kwargs)
        self.ending_mobject = mobject2
        self.mobject.SHOULD_BUFF_POINTS = \
            mobject1.SHOULD_BUFF_POINTS and mobject2.SHOULD_BUFF_POINTS
        self.reference_mobjects.append(mobject2)
        self.name += "To" + str(mobject2)

        if black_out_extra_points and count2 < count1:
            #Ensure redundant pixels fade to black
            indices = np.arange(
                0, count1-1, float(count1) / count2
            ).astype('int')
            temp = np.zeros(mobject2.points.shape)
            temp[indices] = mobject2.rgbs[indices]
            mobject2.rgbs = temp
            self.non_redundant_m2_indices = indices
Exemplo n.º 2
0
 def __init__(self, AnimationClass, mobjects, **kwargs):
     centers = [mob.get_center() for mob in mobjects]
     kwargs["mobject"] = Mobject().add_points(centers)
     self.centers_container = AnimationClass(**kwargs)
     kwargs.pop("mobject")
     Animation.__init__(self, Mobject(*mobjects), **kwargs)
     self.name = str(self) + AnimationClass.__name__
Exemplo n.º 3
0
 def __init__(self, value_function, **kwargs):
     """
     Value function should return a real value 
     depending on the state of the surrounding scene    
     """
     digest_config(self, kwargs, locals())
     self.update_mobject()
     Animation.__init__(self, self.mobject, **kwargs)
Exemplo n.º 4
0
 def __init__(self, *animations, **kwargs):
     if "run_time" in kwargs:
         run_time = kwargs.pop("run_time")
     else:
         run_time = sum([anim.run_time for anim in animations])
     self.num_anims = len(animations)
     self.anims = animations
     mobject = animations[0].mobject
     Animation.__init__(self, mobject, run_time = run_time, **kwargs)
Exemplo n.º 5
0
 def __init__(self, mobject, **kwargs):
     self.intermediate = Mobject(color = self.color)
     self.intermediate.add_points([
         point + (x, y, 0)
         for point in self.mobject.points
         for x in [-1, 1]
         for y in [-1, 1]
     ])
     Animation.__init__(self, mobject, **kwargs)        
Exemplo n.º 6
0
 def __init__(self, homotopy, mobject, **kwargs):
     """
     Homotopy a function from (x, y, z, t) to (x', y', z')
     """
     def function_at_time_t(t):
         return lambda p : homotopy(p[0], p[1], p[2], t)
     self.function_at_time_t = function_at_time_t
     digest_config(self, kwargs)
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 7
0
 def __init__(self, animation, **kwargs):
     digest_locals(self)
     self.num_mobject_points = animation.mobject.get_num_points()        
     kwargs.update(dict([
         (attr, getattr(animation, attr))
         for attr in Animation.CONFIG
     ]))
     Animation.__init__(self, animation.mobject, **kwargs)
     self.name = str(self) + str(self.animation)
Exemplo n.º 8
0
    def __init__(self, mobject, ending_mobject, **kwargs):
        #Copy ending_mobject so as to not mess with caller
        ending_mobject = ending_mobject.copy()
        digest_config(self, kwargs, locals())
        mobject.align_data(ending_mobject)
        self.init_path_func()

        Animation.__init__(self, mobject, **kwargs)
        self.name += "To" + str(ending_mobject)  
        self.mobject.stroke_width = ending_mobject.stroke_width
Exemplo n.º 9
0
 def __init__(self, matrix, mobject, **kwargs):
     matrix = np.array(matrix)
     if matrix.shape == (2, 2):
         self.matrix = np.identity(3)
         self.matrix[:2, :2] = matrix
     elif matrix.shape == (3, 3):
         self.matrix = matrix
     else:
         raise "Matrix has bad dimensions"
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 10
0
 def __init__(self, *animations, **kwargs):
     if "run_time" in kwargs:
         run_time = kwargs.pop("run_time")
     else:
         run_time = sum([anim.run_time for anim in animations])
     self.num_anims = len(animations)
     self.anims = (animations)
     mobject = Mobject(*[anim.mobject for anim in self.anims])
     self.last_index = 0
     Animation.__init__(self, mobject, run_time = run_time, **kwargs)
Exemplo n.º 11
0
    def __init__(self, mobject, target_mobject, **kwargs):
        #Copy target_mobject so as to not mess with caller
        self.original_target_mobject = target_mobject
        target_mobject = target_mobject.copy()
        digest_config(self, kwargs, locals())
        mobject.align_data(target_mobject)
        self.init_path_func()

        Animation.__init__(self, mobject, **kwargs)
        self.name += "To" + str(target_mobject)  
Exemplo n.º 12
0
 def __init__(self, AnimationClass, mobjects, **kwargs):
     full_kwargs = AnimationClass.CONFIG
     full_kwargs.update(kwargs)
     full_kwargs["mobject"] = Mobject(*[
         mob.get_point_mobject()
         for mob in mobjects
     ])
     self.centers_container = AnimationClass(**full_kwargs)
     full_kwargs.pop("mobject")
     Animation.__init__(self, Mobject(*mobjects), **full_kwargs)
     self.name = str(self) + AnimationClass.__name__
Exemplo n.º 13
0
    def __init__(self, mobject, ending_mobject, **kwargs):
        mobject, ending_mobject = map(instantiate, [mobject, ending_mobject])
        digest_config(self, kwargs, locals())
        count1, count2 = mobject.get_num_points(), ending_mobject.get_num_points()
        if count2 == 0:
            ending_mobject.add_points([SPACE_WIDTH*RIGHT+SPACE_HEIGHT*UP])
            count2 = ending_mobject.get_num_points()
        Mobject.align_data(mobject, ending_mobject)
        if self.should_black_out_extra_points and count2 < count1:
            self.black_out_extra_points(count1, count2)

        Animation.__init__(self, mobject, **kwargs)
        self.name += "To" + str(ending_mobject)  
        self.mobject.point_thickness = ending_mobject.point_thickness
Exemplo n.º 14
0
 def __init__(self, word, **kwargs):
     self.path = Cycloid(end_theta = np.pi)        
     word_mob = TextMobject(list(word))
     end_word = word_mob.copy()
     end_word.shift(-end_word.get_bottom())
     end_word.shift(self.path.get_corner(DOWN+RIGHT))
     end_word.shift(3*RIGHT)
     self.end_letters = end_word.split()
     for letter in word_mob.split():
         letter.center()
         letter.angle = 0
     unit_interval = np.arange(0, 1, 1./len(word))
     self.start_times = 0.5*(1-(unit_interval))
     Animation.__init__(self, word_mob, **kwargs)
    def __init__(self, body, underwear, hair=None, duration=sf.seconds(1)):
        Animation.__init__(self, body.size(), duration)

        self._body = body
        self._underwear = underwear
        self._hair = hair

        self._mantle = None
        self._shoes = None
        self._legging = None
        self._hauberk = None
        self._armor = None

        self._weapon = None
        self._shield = None
Exemplo n.º 16
0
 def __init__(self, mobject, color = "white", slow_factor = 0.01,
              run_time = 0.1, alpha_func = None,
              *args, **kwargs):
     Animation.__init__(self, mobject, run_time = run_time, 
                        alpha_func = alpha_func,
                        *args, **kwargs)
     self.intermediate = Mobject(color = color)
     self.intermediate.add_points([
         point + (x, y, 0)
         for point in self.mobject.points
         for x in [-1, 1]
         for y in [-1, 1]
     ])
     self.reference_mobjects.append(self.intermediate)
     self.slow_factor = slow_factor
Exemplo n.º 17
0
 def __init__(self,
              mobject,
              axis = None,
              axes = [RIGHT, UP], 
              radians = 2 * np.pi,
              run_time = 20.0,
              alpha_func = None,
              *args, **kwargs):
     Animation.__init__(
         self, mobject,
         run_time = run_time,
         alpha_func = alpha_func,
         *args, **kwargs
     )
     self.axes = [axis] if axis else axes
     self.radians = radians
Exemplo n.º 18
0
    def __init__(self, mobject, ending_mobject, **kwargs):
        mobject = instantiate(mobject)
        #Copy ending_mobject so as to not mess with caller
        ending_mobject = instantiate(ending_mobject).copy()
        digest_config(self, kwargs, locals())
        count1, count2 = mobject.get_num_points(), ending_mobject.get_num_points()
        if count2 == 0:
            ending_mobject.add_points(
                [mobject.get_center()],
                color = BLACK
            )
            count2 = ending_mobject.get_num_points()
        Mobject.align_data(mobject, ending_mobject)
        if self.should_black_out_extra_points and count2 < count1:
            self.black_out_extra_points(count1, count2)

        Animation.__init__(self, mobject, **kwargs)
        self.name += "To" + str(ending_mobject)  
        self.mobject.point_thickness = ending_mobject.point_thickness
Exemplo n.º 19
0
 def __init__(self, clock, **kwargs):
     digest_config(self, kwargs)
     assert(isinstance(clock, Clock))
     rot_kwargs = {
         "axis" : OUT,
         "about_point" : clock.get_center()
     }
     hour_radians = -self.hours_passed*2*np.pi/12
     self.hour_rotation = Rotating(
         clock.hour_hand, 
         radians = hour_radians,
         **rot_kwargs
     )
     self.minute_rotation = Rotating(
         clock.minute_hand, 
         radians = 12*hour_radians,
         **rot_kwargs
     )
     Animation.__init__(self, clock, **kwargs)
Exemplo n.º 20
0
 def __init__(self, clock, **kwargs):
     digest_config(self, kwargs)
     assert(isinstance(clock, Clock))
     rot_kwargs = {
         "axis" : OUT,
         "about_point" : clock.get_center()
     }
     hour_radians = -self.hours_passed*2*np.pi/12
     self.hour_rotation = Rotating(
         clock.hour_hand, 
         radians = hour_radians,
         **rot_kwargs
     )
     self.minute_rotation = Rotating(
         clock.minute_hand, 
         radians = 12*hour_radians,
         **rot_kwargs
     )
     Animation.__init__(self, clock, **kwargs)
Exemplo n.º 21
0
    def __init__(self):
        Animation.__init__(self)
        self.line = 60  # B
        self.key = '2EBR7OCLQ0'
        self.way = 'RETOUR'

        self.namespaces = {
            'ms': 'http://mapserver.gis.umn.edu/mapserver',
            'gml': 'http://www.opengis.net/gml',
            'wfs': 'http://www.opengis.net/wfs',
            'ogc': 'http://www.opengis.net/ogc',
            'cub': 'http://data.bordeaux-metropole.fr',
            'wps': 'http://www.opengis.net/wps/1.0.0',
            'bm': "http://data.bordeaux-metropole.fr/wfs"
        }

        self.uri = "http://data.bordeaux-metropole.fr/wfs?key=%s&REQUEST=GetFeature&SERVICE=WFS&SRSNAME=EPSG%%3A3945&TYPENAME=SV_VEHIC_P&VERSION=1.1.0&Filter=%%3CFilter%%3E%%3CAND%%3E%%3CPropertyIsEqualTo%%3E%%3CPropertyName%%3ERS_SV_LIGNE_A%%3C%%2FPropertyName%%3E%%3CLiteral%%3E%d%%3C%%2FLiteral%%3E%%3C%%2FPropertyIsEqualTo%%3E%%3CPropertyIsEqualTo%%3E%%3CPropertyName%%3ESENS%%3C%%2FPropertyName%%3E%%3CLiteral%%3E%s%%3C%%2FLiteral%%3E%%3C%%2FPropertyIsEqualTo%%3E%%3C%%2FAND%%3E%%3C%%2FFilter%%3E" % (
            self.key, self.line, self.way)
        self.stations = self.get_stations()
        print self.stations
Exemplo n.º 22
0
 def __init__(self, AnimationClass, mobject, arg_creator = None, **kwargs):
     digest_config(self, kwargs)
     for key in "rate_func", "run_time", "lag_ratio":
         if key in kwargs:
             kwargs.pop(key)
     if arg_creator is None:
         arg_creator = lambda mobject : (mobject,)
     self.subanimations = [
         AnimationClass(
             *arg_creator(submob),
             run_time = self.run_time,
             rate_func = squish_rate_func(
                 self.rate_func, beta, beta + self.lag_ratio
             ),
             **kwargs
         )
         for submob, beta in zip(
             mobject, 
             np.linspace(0, 1-self.lag_ratio, len(mobject))
         )
     ]
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 23
0
 def __init__(self, AnimationClass, mobject, arg_creator = None, **kwargs):
     digest_config(self, kwargs)
     for key in "rate_func", "run_time", "lag_ratio":
         if key in kwargs:
             kwargs.pop(key)
     if arg_creator is None:
         arg_creator = lambda mobject : (mobject,)
     self.subanimations = [
         AnimationClass(
             *arg_creator(submob),
             run_time = self.run_time,
             rate_func = squish_rate_func(
                 self.rate_func, beta, beta + self.lag_ratio
             ),
             **kwargs
         )
         for submob, beta in zip(
             mobject, 
             np.linspace(0, 1-self.lag_ratio, len(mobject))
         )
     ]
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 24
0
 def __init__(self):
     Animation.__init__(self)
     r = 1.
     g = 1.
     b = 1.
     self.set_color(r, g, b)
    def __init__(self, body, duration=sf.seconds(1)):
        Animation.__init__(self, body.size(), duration)

        self._body = body
Exemplo n.º 26
0
 def __init__(self, *args, **kwargs):
     return Animation.__init__(self, Group(), *args, **kwargs)
Exemplo n.º 27
0
    def __init__(self, *args, **kwargs):
        """
        Each arg will either be an animation, or an animation class 
        followed by its arguments (and potentially a dict for 
        configuraiton).

        For example, 
        Succession(
            ShowCreation(circle),
            Transform, circle, square,
            Transform, circle, triangle,
            ApplyMethod, circle.shift, 2*UP, {"run_time" : 2},
        )
        """
        animations = []
        state = {
            "animations": animations,
            "curr_class": None,
            "curr_class_args": [],
            "curr_class_config": {},
        }

        def invoke_curr_class(state):
            if state["curr_class"] is None:
                return
            anim = state["curr_class"](*state["curr_class_args"],
                                       **state["curr_class_config"])
            state["animations"].append(anim)
            anim.update(1)
            state["curr_class"] = None
            state["curr_class_args"] = []
            state["curr_class_config"] = {}

        for arg in args:
            if isinstance(arg, Animation):
                animations.append(arg)
                arg.update(1)
                invoke_curr_class(state)
            elif isinstance(arg, type) and issubclass(arg, Animation):
                invoke_curr_class(state)
                state["curr_class"] = arg
            elif isinstance(arg, dict):
                state["curr_class_config"] = arg
            else:
                state["curr_class_args"].append(arg)
        invoke_curr_class(state)
        for anim in animations:
            anim.update(0)

        self.run_times = [anim.run_time for anim in animations]
        if "run_time" in kwargs:
            run_time = kwargs.pop("run_time")
        else:
            run_time = sum(self.run_times)
        self.num_anims = len(animations)
        self.animations = animations
        self.last_index = 0
        #Have to keep track of this run_time, because Scene.play
        #might very well mess with it.
        self.original_run_time = run_time

        mobject = Group(*[anim.mobject for anim in self.animations])
        Animation.__init__(self, mobject, run_time=run_time, **kwargs)
Exemplo n.º 28
0
 def __init__(self, start_val = 0, end_val = 1, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, self.get_mobject_at_alpha(0), **kwargs)
Exemplo n.º 29
0
 def __init__(self, scene, input_value, radius, **kwargs):
     digest_locals(self)
     Animation.__init__(self, Mobject(), **kwargs)
Exemplo n.º 30
0
 def __init__(self, vmobject, **kwargs):
     if not isinstance(vmobject, VMobject):
         raise Exception("DrawBorderThenFill only works for VMobjects")
     self.reached_halfway_point_before = False
     Animation.__init__(self, vmobject, **kwargs)
Exemplo n.º 31
0
 def __init__(self, mobject, update_function, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 32
0
 def __init__(self, start_val=0, end_val=1, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, self.get_mobject_at_alpha(0), **kwargs)
Exemplo n.º 33
0
    def __init__(self, actor, vec):

        Animation.__init__(self, actor)

        self.vector = Vector(vec)
Exemplo n.º 34
0
 def __init__(self, homotopy, mobject, **kwargs):
     """
     Homotopy a function from (x, y, z, t) to (x', y', z')
     """
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 35
0
 def __init__(self):
     Animation.__init__(self)
     self._start = self._milliseconds()
     self._hide_until = 0
Exemplo n.º 36
0
 def __init__(self, pi_creature, destination, *args, **kwargs):
     self.final = deepcopy(pi_creature).move_to(destination)
     self.middle = pi_creature.get_step_intermediate(self.final)
     Animation.__init__(self, pi_creature, *args, **kwargs)
Exemplo n.º 37
0
 def __init__(self, *sub_anims, **kwargs):
     digest_config(self, kwargs, locals())
     sync_animation_run_times_and_rate_funcs(*sub_anims, **kwargs)
     self.run_time = max([a.run_time for a in sub_anims])
     everything = Mobject(*[a.mobject for a in sub_anims])
     Animation.__init__(self, everything, **kwargs)
Exemplo n.º 38
0
 def __init__(self, *sub_anims, **kwargs):
     digest_config(self, kwargs, locals())
     sync_animation_run_times_and_rate_funcs(*sub_anims, **kwargs)
     self.run_time = max([a.run_time for a in sub_anims])
     everything = Mobject(*[a.mobject for a in sub_anims])
     Animation.__init__(self, everything, **kwargs)
Exemplo n.º 39
0
 def __init__(self, mobject, vector, **kwargs):
     radius = mobject.get_width()/2
     radians = np.linalg.norm(vector)/radius
     last_alpha = 0
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 40
0
 def __init__(self, mobject=None, **kwargs):
     if mobject is None:
         mobject = Line(3 * LEFT, 3 * RIGHT)
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 41
0
 def __init__(self, mobject, vector, **kwargs):
     radius = mobject.get_width() / 2
     radians = np.linalg.norm(vector) / radius
     last_alpha = 0
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 42
0
 def __init__(self, mobject, update_function, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 43
0
 def __init__(self, tex_list, **kwargs):
     mobject = TexMobject(self.curr_tex).shift(start_center)
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 44
0
 def __init__(self, mobject, tracked_mobject, **kwargs):
     digest_config(self, kwargs, locals())
     tcp = self.tracked_critical_point
     self.diff = mobject.get_critical_point(tcp) - \
                 tracked_mobject.get_critical_point(tcp)
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 45
0
 def __init__(self, function, mobject, **kwargs):
     digest_config(self, kwargs, locals())
     self.get_nudge_func = lambda alpha_diff : \
         lambda point : point + alpha_diff*function(point)
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 46
0
    def __init__(self) -> None:
        """
        The constructor.
        """

        # Make all of the matplotlib objects
        Animation.__init__(self)
        self.ax = self.figure.subplots(nrows=2, ncols=1)
        self.figure.subplots_adjust(wspace=0.75, hspace=0.75)
        # self.figure.tight_layout()
        self.f = Functionx("(a/(sqrt(2*pi*sigma**2)))*"
                           "exp(-(1/2)*((x - mu)/sigma)**2)")
        self.x = np.linspace(-np.pi, np.pi, 512)
        self.y = self.f(self.x, 1, 1, 1)
        line, = self.ax[0].plot(self.x, self.y)
        f = np.fft.fftshift(np.fft.fft(self.f(self.x, 1, 1, 1))) / len(self.x)
        dx = self.x[1] - self.x[0]
        freq = 2 * np.pi * np.fft.fftshift(np.fft.fftfreq(len(self.x), d=dx))
        line2, = self.ax[1].plot(freq,
                                 np.real(f),
                                 label="Real part",
                                 linewidth=0.5)
        line3, = self.ax[1].plot(freq,
                                 np.imag(f),
                                 label="Imaginary part",
                                 linewidth=0.5)
        line4, = self.ax[1].plot(freq,
                                 np.abs(f),
                                 color="black",
                                 label="Absolute Value",
                                 linewidth=1.0)
        self.ax[1].legend(prop={'size': 6})
        self.ax[1].set_xlim(np.min(freq), np.max(freq))
        self.ax[1].set_xlabel("Angular Frequency")
        self.ax[1].set_ylabel("Amplitude")
        self.ax[1].set_ylim(-0.25, 0.25)
        self.ax[1].set_title("Fourier Transform of f(x)")
        self.ax[1].grid()
        self.ax[0].set_xlim(self.x[0], self.x[-1])
        self.ax[0].set_xlabel("x")
        self.ax[0].set_ylabel("y")
        self.ax[0].set_ylim(-2, 2)
        self.ax[0].set_title("Function f(x)")
        self.ax[0].grid()
        self.line = line
        self.line2 = line2
        self.line3 = line3
        self.line4 = line4
        self.fourier_amps = f
        self.freq = freq
        xbounds = self.ax[0].get_xlim()
        ybounds = self.ax[0].get_ylim()
        s = (-xbounds[0] + xbounds[1]) / 50 + xbounds[0]
        y = (ybounds[1] - ybounds[0]) * 0.8 + ybounds[0]
        # y = 100
        self.text = self.ax[0].text(s, y, r"f(x) = $%s$" % self.f.latex_repr)
        self.text.set_bbox({"facecolor": "white", "alpha": 1.0})
        self.autoaddartists = True

        # Tkinter main window
        self.window = tk.Tk()

        # Thanks to stackoverflow user rudivonstaden for
        # giving a way to get the colour of the tkinter widgets:
        # https://stackoverflow.com/questions/11340765/
        # default-window-colour-tkinter-and-hex-colour-codes
        #
        #     https://stackoverflow.com/q/11340765
        #     [Question by user user2063:
        #      https://stackoverflow.com/users/982297/user2063]
        #
        #     https://stackoverflow.com/a/11342481
        #     [Answer by user rudivonstaden:
        #      https://stackoverflow.com/users/1453643/rudivonstaden]
        #
        colour = self.window.cget('bg')
        if colour == 'SystemButtonFace':
            colour = "#F0F0F0"

        # Thanks to stackoverflow user user1764386 for
        # giving a way to change the background colour of a plot.
        #
        #    https://stackoverflow.com/q/14088687
        #    [Question by user user1764386:
        #     https://stackoverflow.com/users/1764386/user1764386]
        #
        self.figure.patch.set_facecolor(colour)

        self.window.title("Plot")
        self.window.configure()

        # Canvas
        self.canvas = \
            backend_tkagg.FigureCanvasTkAgg(
                self.figure,
                master=self.window
            )
        self.canvas.get_tk_widget().grid(row=0,
                                         column=0,
                                         rowspan=19,
                                         columnspan=2)
        self.canvas.get_tk_widget().bind("<B1-Motion>",
                                         self.update_function_by_mouse)
        self.canvas.get_tk_widget().bind("<Button-1>",
                                         self.update_function_by_mouse)

        # All the other widgets
        self.enterfunctionlabel = tk.Label(self.window,
                                           text="Enter function f(x)")
        self.enterfunctionlabel.grid(row=0,
                                     column=3,
                                     columnspan=2,
                                     sticky=tk.W + tk.E + tk.S,
                                     padx=(10, 10))
        self.enter_function = tk.Entry(self.window)
        self.enter_function.bind("<Return>", self.update_function_by_entry)
        self.enter_function.grid(row=1,
                                 column=3,
                                 columnspan=2,
                                 sticky=tk.W + tk.E + tk.N + tk.S,
                                 padx=(10, 10))
        self.enter_function_button = tk.Button(
            self.window, text="OK", command=self.update_function_by_entry)
        self.enter_function_button.grid(row=2,
                                        column=3,
                                        columnspan=2,
                                        sticky=tk.W + tk.E + tk.N,
                                        padx=(10, 10))
        self.function_menu_dict = {
            "Normal Distribution":
            "a*exp(-(x-mu)**2/(2*sigma**2 ))"
            "/sqrt(2*pi*sigma**2)",
            "Sinusoidal Function 1":
            "a*sin(20*k*(x - phi))",
            "Sinusoidal Function 2":
            "a*sin(50*k*(x - phi))",
            "Sinc Function":
            "a*sinc(20*k*(x - phi))",
            "Rectangle Function":
            "a*rect(k*(x - b))",
            "Wavepacket":
            "a*sin(50*k*(x - phi))*exp(-(x-b)**2/"
            "(2*sigma**2 ))/sqrt(2*pi*sigma**2)",
            "Noise":
            "a*noise(k*(x - b))",
            "Two Gaussians":
            "a*exp(-0.5*(x-c)**2/sigma_1**2)"
            "/sqrt(2*pi*sigma_1**2) + "
            "b*exp(-0.5*(x+d)**2/sigma_2**2)/sqrt(2*pi*sigma_2**2)"
        }
        self.function_menu_string = tk.StringVar(self.window)
        self.function_menu_string.set("Preset function f(x)")
        self.function_menu = tk.OptionMenu(
            self.window,
            self.function_menu_string,
            *tuple(key for key in self.function_menu_dict),
            # text="Choose a preset potential"
            command=self.update_function_by_preset)
        self.function_menu.grid(row=3,
                                column=3,
                                columnspan=2,
                                sticky=tk.W + tk.E + tk.S,
                                padx=(10, 10))
        self.sliderslist = []
        self.set_sliders()
Exemplo n.º 47
0
    def __init__(self, *args, **kwargs):
        """
        Each arg will either be an animation, or an animation class 
        followed by its arguments (and potentially a dict for 
        configuration).

        For example, 
        Succession(
            ShowCreation(circle),
            Transform, circle, square,
            Transform, circle, triangle,
            ApplyMethod, circle.shift, 2*UP, {"run_time" : 2},
        )
        """
        animations = []
        state = {
            "animations": animations,
            "curr_class": None,
            "curr_class_args": [],
            "curr_class_config": {},
        }

        def invoke_curr_class(state):
            if state["curr_class"] is None:
                return
            anim = state["curr_class"](*state["curr_class_args"],
                                       **state["curr_class_config"])
            state["animations"].append(anim)
            anim.update(1)
            state["curr_class"] = None
            state["curr_class_args"] = []
            state["curr_class_config"] = {}

        for arg in args:
            if isinstance(arg, Animation):
                animations.append(arg)
                arg.update(1)
                invoke_curr_class(state)
            elif isinstance(arg, type) and issubclass(arg, Animation):
                invoke_curr_class(state)
                state["curr_class"] = arg
            elif isinstance(arg, dict):
                state["curr_class_config"] = arg
            else:
                state["curr_class_args"].append(arg)
        invoke_curr_class(state)
        for anim in animations:
            anim.update(0)

        animations = filter(lambda x: not (x.empty), animations)

        self.run_times = [anim.run_time for anim in animations]
        if "run_time" in kwargs:
            run_time = kwargs.pop("run_time")
            warnings.warn(
                "Succession doesn't currently support explicit run_time.")
        run_time = sum(self.run_times)
        self.num_anims = len(animations)
        if self.num_anims == 0:
            self.empty = True
        self.animations = animations
        #Have to keep track of this run_time, because Scene.play
        #might very well mess with it.
        self.original_run_time = run_time

        # critical_alphas[i] is the start alpha of self.animations[i]
        # critical_alphas[i + 1] is the end alpha of self.animations[i]
        critical_times = np.concatenate(([0], np.cumsum(self.run_times)))
        self.critical_alphas = map(
            lambda x: np.true_divide(x, run_time),
            critical_times) if self.num_anims > 0 else [0.0]

        # self.scene_mobjects_at_time[i] is the scene's mobjects at start of self.animations[i]
        # self.scene_mobjects_at_time[i + 1] is the scene mobjects at end of self.animations[i]
        self.scene_mobjects_at_time = [None for i in range(self.num_anims + 1)]
        self.scene_mobjects_at_time[0] = Group()
        for i in range(self.num_anims):
            self.scene_mobjects_at_time[
                i + 1] = self.scene_mobjects_at_time[i].copy()
            self.animations[i].clean_up(self.scene_mobjects_at_time[i + 1])

        self.current_alpha = 0
        self.current_anim_index = 0  # If self.num_anims == 0, this is an invalid index, but so it goes
        if self.num_anims > 0:
            self.mobject = self.scene_mobjects_at_time[0]
            self.mobject.add(self.animations[0].mobject)
        else:
            self.mobject = Group()

        Animation.__init__(self, self.mobject, run_time=run_time, **kwargs)
Exemplo n.º 48
0
 def __init__(self, tex_list, **kwargs):
     mobject = TexMobject(self.curr_tex).shift(start_center)
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 49
0
 def __init__(self, vmobject, **kwargs):
     if not isinstance(vmobject, VMobject):
         raise Exception("DrawBorderThenFill only works for VMobjects")
     self.reached_halfway_point_before = False
     Animation.__init__(self, vmobject, **kwargs)
Exemplo n.º 50
0
 def __init__(self, homotopy, mobject, **kwargs):
     """
     Homotopy a function from (x, y, z, t) to (x', y', z')
     """
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 51
0
 def __init__(self, mobject, path, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 52
0
 def __init__(self, homotopy, *args, **kwargs):
     """
     Homotopy a function from (x, y, z, t) to (x', y', z')
     """
     self.homotopy = homotopy
     Animation.__init__(self, *args, **kwargs)
Exemplo n.º 53
0
 def __init__(self, mobject, tracked_mobject, **kwargs):
     digest_config(self, kwargs, locals())
     tcp = self.tracked_critical_point
     self.diff = mobject.get_critical_point(tcp) - \
                 tracked_mobject.get_critical_point(tcp)
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 54
0
 def __init__(self, mobject, path, **kwargs):
     digest_config(self, kwargs, locals())
     Animation.__init__(self, mobject, **kwargs)
Exemplo n.º 55
0
 def __init__(self, folder):
     Animation.__init__(self)
     self.load(folder)
Exemplo n.º 56
0
 def __init__(self):
     Animation.__init__(self)