Transformation with texts in equations

The objective is to transform step by step the completing square process with x^2 + 26x = 27. Have been facing errors like the list is out of range and there are overlapping of some characters as well after making some changes.
Requesting to give me a script that achieves the objective with simple explanation.
Thanks.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>class CompletingTheSquare(Scene):
def construct(self):
First equation
equation = MathTex(
"x^2", #0
"+", #1
"26x", #2
"=", #3
"27" #4
)
equation.to_edge(UP + LEFT) # Move to the top-left edge
Display the equation
self.play(Write(equation))
self.wait(2)
2nd step
equation2 = MathTex(
"x^2", #0
"+", #1
"26x", #2
"+ 169", #3
"=", #4
"27", #5
"+ 169" #6
)
equation2.align_to(equation, LEFT) # Move to the same position as equation
equation2.align_to(equation, UP) # Move to the same position as equation
Group1 (x^2 + 26x) & (= 27)
same_terms1 = VGroup(equation[0], equation[1], equation[2])
same_terms2 = VGroup(equation[3], equation[4])
Group in new (x^2 + 26x) & (= 27)
same_terms3 = VGroup(equation2[0], equation2[1], equation2[2])
same_terms4 = VGroup(equation2[4], equation2[5])
Transform
self.play(
Transform(same_terms1, same_terms3),
Transform(same_terms2, same_terms4)
)
self.play(
Write(equation2[3]),
Write(equation2[6])
)
self.wait()
3 step
equation3 = MathTex(
"x^2", #0
"+", #1
"26x" #2
"+ 169", #3
"=", #4
"196" #5
)
equation3.align_to(equation2, LEFT) # Move to the same position as the scaled equation
equation3.align_to(equation2, UP) # Move to the same position as the scaled equation
Group in 2nd step (27 + 169)
same_terms5 = VGroup(equation2[0], equation2[1], equation2[2], equation2[3], equation2[4])
same_terms6 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4])
same_terms7 = VGroup(equation2[5], equation2[6])
Display 169 + 27 becoming 196
self.play(Transform(same_terms5, same_terms6))
self.play(Transform(same_terms7, equation3[5]))
self.wait(1)
Last step
final_equation = MathTex(
"(x + 13)^2", #0
"=", #1
"196") #2
final_equation.align_to(new_equation, LEFT)
final_equation.align_to(new_equation, UP)
Grouping x^2 + 26x + 169 = becomes (x+13)^2 =
same_terms8 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4])
same_terms9 = VGroup(final_equation[0], final_equation[1])
Animate the transformation to the new equation and remove the old one
self.play(Transform(same_terms8, sameterms9))
self.play(Transform(equation3[5], final_equation[2]))
self.wait(2)
</code>
<code>class CompletingTheSquare(Scene): def construct(self): First equation equation = MathTex( "x^2", #0 "+", #1 "26x", #2 "=", #3 "27" #4 ) equation.to_edge(UP + LEFT) # Move to the top-left edge Display the equation self.play(Write(equation)) self.wait(2) 2nd step equation2 = MathTex( "x^2", #0 "+", #1 "26x", #2 "+ 169", #3 "=", #4 "27", #5 "+ 169" #6 ) equation2.align_to(equation, LEFT) # Move to the same position as equation equation2.align_to(equation, UP) # Move to the same position as equation Group1 (x^2 + 26x) & (= 27) same_terms1 = VGroup(equation[0], equation[1], equation[2]) same_terms2 = VGroup(equation[3], equation[4]) Group in new (x^2 + 26x) & (= 27) same_terms3 = VGroup(equation2[0], equation2[1], equation2[2]) same_terms4 = VGroup(equation2[4], equation2[5]) Transform self.play( Transform(same_terms1, same_terms3), Transform(same_terms2, same_terms4) ) self.play( Write(equation2[3]), Write(equation2[6]) ) self.wait() 3 step equation3 = MathTex( "x^2", #0 "+", #1 "26x" #2 "+ 169", #3 "=", #4 "196" #5 ) equation3.align_to(equation2, LEFT) # Move to the same position as the scaled equation equation3.align_to(equation2, UP) # Move to the same position as the scaled equation Group in 2nd step (27 + 169) same_terms5 = VGroup(equation2[0], equation2[1], equation2[2], equation2[3], equation2[4]) same_terms6 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4]) same_terms7 = VGroup(equation2[5], equation2[6]) Display 169 + 27 becoming 196 self.play(Transform(same_terms5, same_terms6)) self.play(Transform(same_terms7, equation3[5])) self.wait(1) Last step final_equation = MathTex( "(x + 13)^2", #0 "=", #1 "196") #2 final_equation.align_to(new_equation, LEFT) final_equation.align_to(new_equation, UP) Grouping x^2 + 26x + 169 = becomes (x+13)^2 = same_terms8 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4]) same_terms9 = VGroup(final_equation[0], final_equation[1]) Animate the transformation to the new equation and remove the old one self.play(Transform(same_terms8, sameterms9)) self.play(Transform(equation3[5], final_equation[2])) self.wait(2) </code>
class CompletingTheSquare(Scene):
def construct(self):
First equation
equation = MathTex(
"x^2",  #0
"+",    #1
"26x",  #2
"=",    #3
"27"    #4
)
equation.to_edge(UP + LEFT)  # Move to the top-left edge
Display the equation
self.play(Write(equation))
self.wait(2)
2nd step
equation2 = MathTex(
"x^2",      #0
"+",        #1
"26x",      #2      
"+ 169",    #3
"=",        #4
"27",       #5
"+ 169"     #6
)
equation2.align_to(equation, LEFT)  # Move to the same position as equation
equation2.align_to(equation, UP)  # Move to the same position as equation
Group1 (x^2 + 26x) & (= 27)
same_terms1 = VGroup(equation[0], equation[1], equation[2])
same_terms2 = VGroup(equation[3], equation[4])
Group in new (x^2 + 26x) & (= 27)
same_terms3 = VGroup(equation2[0], equation2[1], equation2[2])
same_terms4 = VGroup(equation2[4], equation2[5])
Transform
self.play(
Transform(same_terms1, same_terms3),
Transform(same_terms2, same_terms4)
)
self.play(
Write(equation2[3]),
Write(equation2[6])
)
self.wait()
3 step
equation3 = MathTex(
"x^2",    #0
"+",      #1
"26x"     #2
"+ 169",  #3
"=",      #4
"196"     #5
)
equation3.align_to(equation2, LEFT)  # Move to the same position as the scaled equation
equation3.align_to(equation2, UP)  # Move to the same position as the scaled equation
Group in 2nd step (27 + 169)
same_terms5 = VGroup(equation2[0], equation2[1], equation2[2], equation2[3], equation2[4])
same_terms6 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4])
same_terms7 = VGroup(equation2[5], equation2[6])
Display 169 + 27 becoming 196
self.play(Transform(same_terms5, same_terms6))
self.play(Transform(same_terms7, equation3[5]))
self.wait(1)
Last step
final_equation = MathTex(
"(x + 13)^2",  #0
"=",           #1
"196")         #2
final_equation.align_to(new_equation, LEFT)  
final_equation.align_to(new_equation, UP)  
Grouping x^2 + 26x + 169 = becomes (x+13)^2 =
same_terms8 = VGroup(equation3[0], equation3[1], equation3[2], equation3[3], equation3[4])
same_terms9 = VGroup(final_equation[0], final_equation[1])
Animate the transformation to the new equation and remove the old one
self.play(Transform(same_terms8, sameterms9))
self.play(Transform(equation3[5], final_equation[2]))
self.wait(2)

I’m just not understanding how manim sees the grouping instructions. I tried putting the elements from different equations in the groups, sometimes it did approximately what I wanted. Just want the equations to transformed one after the other correctly.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật