Wednesday 29 September 2021

How to apply two tranformations one after the other in manim?

I wanted to apply two linear transformations with matrices one after the other. Here is the code for one transformation:

 from manim import *

class LT(LinearTransformationScene):
def __init__(self):
    LinearTransformationScene.__init__(
        self,
        show_coordinates=True,
        leave_ghost_vectors=True,
    )

def construct(self):
    matrix = [[1, 1], [0, 1]]
    self.apply_matrix(matrix)
    self.wait()

But I want to apply another transformation after this. I tried using the same code again with different matrix:

 from manim import *

class LT(LinearTransformationScene):
def __init__(self):
    LinearTransformationScene.__init__(
        self,
        show_coordinates=True,
        leave_ghost_vectors=True,
    )

def construct(self):
    matrix = [[1, 1], [0, 1]]
    self.apply_matrix(matrix)
    self.wait()

def construct(self):
    matrix = [[2, 1], [3, 1]]
    self.apply_matrix(matrix)
    self.wait()`

But that didnt work.. Gives the error:

 IndentationError: unindent does not match any outer indentation level

This must be very simple. But I have no idea- didnt found anything in the documentation or search results.Any help is greatly appreciated.


Update: I tried changing the names of the matrix:

from manim import *

class LT(LinearTransformationScene):
    def __init__(self):
        LinearTransformationScene.__init__(
            self,
            show_coordinates=True,
            leave_ghost_vectors=True,
        )

    def construct(self):
        matrix1 = [[1, 1], [0, 1]]
        self.apply_matrix(matrix1)
        self.wait()


    def construct(self):
        matrix2 = [[2, 1], [3, 1]]
        self.apply_matrix(matrix2)
        self.wait()

This time, no errors were given but the transformation didnt work correctly. Only the last matrix was rendered. What might have happened?



from How to apply two tranformations one after the other in manim?

No comments:

Post a Comment