that_one_nigga_you_k

versão parada

Jan 18th, 2025
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.04 KB | None | 0 0
  1. from manim import *
  2.  
  3. config.pixel_height = 1920
  4. config.pixel_width = 1080
  5. config.frame_height = 16
  6. config.frame_width = 9
  7. config.frame_rate = 60
  8.  
  9. class fft(MovingCameraScene):
  10.     center_point = ORIGIN
  11.     slow_factor = 0.1
  12.  
  13.     def get_fft_coefficients_of_path(self, path, n_samples=2048, n_freqs=256):
  14.         dt = 1 / n_samples
  15.         ts = np.arange(0, 1, dt)
  16.         samples = np.array([
  17.             path.point_from_proportion(t)
  18.             for t in ts
  19.         ])
  20.         samples -= self.center_point
  21.         complex_samples = samples[:, 0] + 1j * samples[:, 1]
  22.        
  23.         coeffs = np.fft.fft(complex_samples)
  24.         freqs = np.fft.fftfreq(n_samples, 1/n_samples)
  25.  
  26.         sfreqs = zip(coeffs, freqs)
  27.         p = sorted(sfreqs, key=lambda f: abs(f[1]))
  28.         cs = [a[0] / n_samples for a in p]
  29.         fs = [a[1] for a in p]
  30.         return cs[:n_freqs], fs[:n_freqs]
  31.  
  32.     def get_path(self):
  33.         svg_mob = SVGMobject("/home/narciso/Pictures/eu.svg").scale(1)
  34.         svg_mob.scale_to_fit_height(6)
  35.         path = svg_mob
  36.         path.set_fill(opacity=0)
  37.         path.set_stroke(WHITE, 1)
  38.         return path
  39.  
  40.     def construct(self):
  41.         paths = self.get_path()
  42.         for path in paths:
  43.             coefs, freqs = self.get_fft_coefficients_of_path(path, n_samples=2048, n_freqs=20)
  44.  
  45.             self.play(Create(path))
  46.             self.wait(2)
  47.  
  48.             vectorsCircles = VGroup()
  49.             origin = ORIGIN
  50.             strokewidth = 4
  51.             for i in range(len(freqs)):
  52.                 dummy = Line(
  53.                     start=ORIGIN,
  54.                     end=[np.real(coefs[i]), np.imag(coefs[i]), 0],
  55.                     stroke_width=strokewidth
  56.                 )
  57.                 circ = Circle(radius=np.abs(coefs[i])).set_stroke(width=0.5*strokewidth, color=RED)
  58.                 strokewidth *= 0.9
  59.                 vectorsCircles += VGroup(dummy, circ).shift(origin)
  60.                 origin = dummy.get_end()
  61.  
  62.             self.play(FadeIn(vectorsCircles), run_time=0.5)
  63.             self.wait()
  64.  
  65.             dot = always_redraw(lambda: Dot(vectorsCircles[-1][0].get_end(), radius=0.04, color=GREEN))
  66.  
  67.             trace = VMobject().set_points([vectorsCircles[-1][0].get_end()]).set_color(YELLOW)
  68.             self.add(trace, dot)
  69.  
  70.             def vectorsUpdater(mobj, dt):
  71.                 origin = mobj[0][0].get_end()
  72.                 for i in range(1, len(freqs)):
  73.                     mobj[i][0].rotate(2 * PI * dt * freqs[i] * self.slow_factor, about_point=mobj[i][0].get_start())
  74.                     mobj[i].shift(origin - mobj[i][0].get_start())
  75.                     origin = mobj[i][0].get_end()
  76.                 trace.add_smooth_curve_to(mobj[-1][0].get_end())
  77.             vectorsCircles.add_updater(vectorsUpdater)
  78.  
  79.             self.wait(1 / self.slow_factor)
  80.  
  81.             # Remove qualquer movimento da câmera
  82.             vectorsCircles.remove_updater(vectorsUpdater)
  83.  
  84.             self.wait(1 / self.slow_factor)
  85.  
  86.             vectorsCircles.remove_updater(vectorsUpdater)
  87.         self.wait(2)
  88.  
Add Comment
Please, Sign In to add comment