Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from manim import *
- import numpy as np
- 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
- 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
- )
- self.wait(2)
Add Comment
Please, Sign In to add comment