Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from manim import *
- import numpy as np
- import random
- config.pixel_height = 1920
- config.pixel_width = 1080
- config.frame_height = 16
- config.frame_width = 9
- config.frame_rate = 60
- class Funcao(Scene):
- def construct(self):
- # Criando o plano cartesiano personalizado
- primeiraEq = MathTex(r"x + y + z = 4")
- primeiraEq5 = MathTex(r"xy + yz + xz = 1", font_size = 36)
- primeiraEq14 = MathTex(r"xyz = - 6", font_size = 36)
- imaginacao = Tex("Imaginação")
- se_a_Gente = Tex("Se a gente imaginar um polinômio de terceiro grau", font_size=36)
- tudo = Tex("Tudo fica fácil")
- txt_grupo = VGroup(imaginacao, se_a_Gente, tudo)
- txt_grupo.arrange(DOWN, aligned_edge=LEFT, buff=0.5)
- txt_grupo.to_corner(UP)
- for txt in txt_grupo:
- self.play(Write(txt))
- self.wait(0.5)
- self.wait(1)
- eq1 = MathTex("r_1 + r_2 + r_3", "=", "-\\frac{b}{a}", font_size = 36)
- eq2 = MathTex("r_1 r_2 + r_2 r_3 + r_3 r_1", "=", "\\frac{c}{a}", font_size = 36)
- eq3 = MathTex("r_1 r_2 r_3", "=", "-\\frac{d}{a}", font_size = 36)
- eq_group = VGroup(eq1, eq2, eq3)
- eq_group.arrange(DOWN, aligned_edge=LEFT, buff=0.5)
- eq_group.next_to(tudo, DOWN, buff=1)
- eq_group.to_edge(LEFT)
- # Novas equações com substituições
- # Adicionando novas partes (continuação das equações)
- new_part1 = MathTex("\\quad \\Rightarrow \\quad", "x + y + z", "=", "-\\frac{b}{a}", font_size = 36).next_to(eq1, RIGHT)
- new_part2 = MathTex("\\quad \\Rightarrow \\quad", "xy + yz + zx", "=", "\\frac{c}{a}", font_size = 36).next_to(eq2, RIGHT)
- new_part3 = MathTex("\\quad \\Rightarrow \\quad", "xyz", "=", "-\\frac{d}{a}", font_size = 36).next_to(eq3, RIGHT)
- new_eq_parts = VGroup(new_part1, new_part2, new_part3)
- solucao1 = MathTex(r"-\frac{b}{a}", "=", r"4")
- solucao2 = MathTex(r"\frac{c}{a}", "=", r"1")
- solucao3 = MathTex(r"-\frac{d}{a}", "=", r"-6")
- solucao_group = VGroup(solucao1, solucao2, solucao3)
- solucao_group.arrange(DOWN, aligned_edge=LEFT, buff=0.5)
- solucao_group.next_to(new_eq_parts, DOWN, buff=1)
- solucao_group.set_x(0)
- for eq in eq_group:
- self.play(Write(eq))
- self.wait(0.5)
- self.play(Write(new_eq_parts))
- self.wait(2)
- self.play(Write(solucao_group))
- self.wait(2)
- self.play(solucao_group.animate.set_color_by_gradient(RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE))
- self.wait(2)
- self.play(Unwrite(VGroup(txt_grupo, eq_group, new_eq_parts, solucao_group)))
- npl = NumberPlane(
- x_range=[-config.frame_width / 2, config.frame_width / 2],
- y_range=[-config.frame_height / 2, config.frame_height / 2],
- axis_config={"stroke_color": WHITE}
- )
- npl.add_coordinates()
- self.play(Create(npl))
- # Função de terceiro grau: f(x) = ax³ + bx² + cx + d
- a = ValueTracker(0)
- b = ValueTracker(0)
- c = ValueTracker(0)
- d = ValueTracker(0)
- def cubic_function(x):
- return a.get_value() * x**3 + b.get_value() * x**2 + c.get_value() * x + d.get_value()
- # Desenhar gráfico inicial
- graph = always_redraw(lambda: npl.plot(cubic_function, color=YELLOW))
- self.play(Create(graph))
- # Criando exibição do valor de 'a'
- a_text = always_redraw(lambda:
- MathTex(f"a = {a.get_value():.2f}").to_corner(UP + LEFT)
- )
- self.add(a_text)
- b_text = always_redraw(lambda:
- MathTex(f"b = {b.get_value():.2f}").next_to(a_text, DOWN)
- )
- c_text = always_redraw(lambda:
- MathTex(f"c = {c.get_value():.2f}").next_to(b_text, DOWN)
- )
- d_text = always_redraw(lambda:
- MathTex(f"d = {d.get_value():.2f}").next_to(c_text, DOWN)
- )
- self.add(b_text, c_text, d_text)
- # Função para encontrar as raízes reais do polinômio
- def find_real_roots():
- coef = [a.get_value(), b.get_value(), c.get_value(), d.get_value()]
- roots = np.roots(coef)
- # Retornar apenas raízes reais
- real_roots = [root.real for root in roots if np.isreal(root)]
- return real_roots
- # Inicializar pontos de interseção
- intersection_circles = always_redraw(lambda:
- VGroup(*[
- Circle(radius=0.1, color=RED).move_to(npl.c2p(root, 0))
- for root in find_real_roots()
- ])
- )
- self.add(intersection_circles)
- # Lista com os valores para as animações
- values = [
- (5, 3, -2, 1),
- (-5, -3, 2, -1),
- (2, -4, 3, 1),
- (1.5, -4, -8, 7),
- (-1.5, 10, 0.3, -5),
- (-1.5, 10, -30, -5),
- (1.5, -10, 3, 2.5),
- (2.5, -3, -5, 2)
- ]
- # Loop para aplicar as animações com os valores da lista
- for a_val, b_val, c_val, d_val in values:
- self.play(
- a.animate.set_value(a_val),
- b.animate.set_value(b_val),
- c.animate.set_value(c_val),
- d.animate.set_value(d_val),
- run_time=5,
- rate_func=rate_functions.ease_in_out_sine
- )
- # Flutuação aleatória por um tempo determinado
- for _ in range(20): # Número de variações aleatórias
- self.play(
- a.animate.set_value(random.uniform(-1, 1)),
- b.animate.set_value(random.uniform(-1, 1)),
- c.animate.set_value(random.uniform(-1, 1)),
- d.animate.set_value(random.uniform(-1, 1)),
- run_time=1,
- rate_func=rate_functions.linear
- )
- self.wait(2)
- leftover = VGroup()
- for obj in self.mobjects:
- if issubclass(obj.__class__, VMobject):
- leftover += obj
- self.play(Unwrite(leftover))
- sistema = MathTex(r"\left\{ \begin{aligned} &x + y + z = 4 \\ &x^2 + y^2 + z^2 = 14 \\ &x^3 + y^3 + z^3 = 34 \end{aligned} \right.")
- sistema.to_edge(UP)
- self.wait(1)
- class intro(Scene):
- def construct(self):
- imaginacao = Tex("Imaginação")
- se_a_Gente = Tex("Se a gente imaginar um polinômio de terceiro grau, tudo fica fácil")
Add Comment
Please, Sign In to add comment