Repository: ManimCommunity/manim
File: manim/animation/speedmodifier.py (Python)

Code before:
                lag_ratio=anim.lag_ratio,
            )

        self.rate_func = self.anim.rate_func if rate_func is None else rate_func

        # A function where, f(0) = 0, f'(0) = m, f'( f-1(1) ) = n
        # m being initial speed, n being final speed
        # Following function obtained when conditions applied to vertical parabola
        self.speed_modifier = lambda x, m, n: (n * n - m * m) * x * x / 4 + m * x

        # f-1(1), returns x for which f(x) = 1 in `speed_modifier` function
        self.f_inv_1 = lambda m, n: 2 / (m + n)

        if 0 not in speedinfo:
            speedinfo[0] = 1
        if 1 not in speedinfo:
            speedinfo[1] = sorted(speedinfo.items())[-1][1]

        self.speedinfo = dict(sorted(speedinfo.items()))
        self.functions = []
        self.conditions = []

        # To the total time
        total_time = self.get_total_time()

        prevnode = 0
        m = self.speedinfo[0]
        curr_time = 0
        for node, n in list(self.speedinfo.items())[1:]:
            dur = node - prevnode
            self.conditions.append(
                lambda x, curr_time=curr_time, m=m, n=n, dur=dur: curr_time / total_time
                <= x
                <= (curr_time + self.f_inv_1(m, n) * dur) / total_time
            )
            self.functions.append(
                lambda x, dur=dur, m=m, n=n, prevnode=prevnode, curr_time=curr_time: self.speed_modifier(
                    (total_time * x - curr_time) / dur, m, n
                )
                * dur
                + prevnode
            )
            curr_time += self.f_inv_1(m, n) * dur
            prevnode = node
            m = n

        def func(x):
            newx = piecewise(
                self.rate_func(x),
                [condition(self.rate_func(x)) for condition in self.conditions],
                self.functions,

Review comment (suggestion):
```suggestion

    # if speed factors for the starting node (0) and the final node (1) are
    # not set, set them to 1 and the penultimate factor, respectively
```

Code after:
                run_time=anim.run_time,
                rate_func=anim.rate_func,
                lag_ratio=anim.lag_ratio,
            )
        else:
            self.anim = self.setup(anim)

        if affects_speed_updaters:
            assert (
                ChangeSpeed.is_changing_dt is False
            ), "Only one animation at a time can play that changes speed (dt) for ChangeSpeed updaters"
            ChangeSpeed.is_changing_dt = True
            self.t = 0
        self.affects_speed_updaters = affects_speed_updaters

        self.rate_func = self.anim.rate_func if rate_func is None else rate_func

        # A function where, f(0) = 0, f'(0) = initial speed, f'( f-1(1) ) = final speed
        # Following function obtained when conditions applied to vertical parabola
        self.speed_modifier = lambda x, init_speed, final_speed: (
            (final_speed**2 - init_speed**2) * x**2 / 4 + init_speed * x
        )

        # f-1(1), returns x for which f(x) = 1 in `speed_modifier` function
        self.f_inv_1 = lambda init_speed, final_speed: 2 / (init_speed + final_speed)

        # if speed factors for the starting node (0) and the final node (1) are
        # not set, set them to 1 and the penultimate factor, respectively
        if 0 not in speedinfo:
            speedinfo[0] = 1
        if 1 not in speedinfo:
            speedinfo[1] = sorted(speedinfo.items())[-1][1]

        self.speedinfo = dict(sorted(speedinfo.items()))
        self.functions = []
        self.conditions = []

        # Get the time taken by amimation if `run_time` is assumed to be 1
        scaled_total_time = self.get_scaled_total_time()

        prevnode = 0
        init_speed = self.speedinfo[0]
        curr_time = 0
        for node, final_speed in list(self.speedinfo.items())[1:]:
            dur = node - prevnode

            def condition(
                t,
                curr_time=curr_time,
                init_speed=init_speed,
                final_speed=final_speed,