Manim, Transform two functions into one

Viewed 138

I want to use Manim to explain Amplitude Modulation. I have produced the following code:

from manim import *

class SomeAnimations(Scene):
def construct(self):

    cos_func = FunctionGraph(
        lambda t: np.cos(2 * t)+2.5,
        color=RED,
    )

    sin_func_1 = FunctionGraph(
        lambda t: np.sin(14 * t)-2.5,
        color=BLUE,
    )

    cos_sin_func_1 = FunctionGraph(
        lambda t: np.sin(14 * t) * np.cos(2*t) + np.sin(14 * t),
        color=ORANGE,
    )

    self.add(cos_func, sin_func_1)
    self.wait(1)
    self.play(Transform(cos_func, cos_sin_func_1), Transform(sin_func_1, cos_sin_func_1))
    self.wait(1)

As can be seen in the code, I use two different Transform classes. I was wondering if this can be narrowed down to one Transform class. Also, I want to know if instead of defining another Functiongraph there is another way to get the AM signal. I have tried to use the following code:

self.play(Transform(cos_func, (sin_func_1 * cos_func + cos_func)))

However, the compiler gives the following error:

TypeError: unsupported operand type(s) for *: 'FunctionGraph' and 'FunctionGraph'

I hope someone can give me feedback on this.

Thank you

0 Answers
Related