mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Small tweaks to Fourier series animations
This commit is contained in:
parent
bf8f517b49
commit
c4449fdfb8
1 changed files with 54 additions and 6 deletions
|
@ -313,12 +313,7 @@ class FourierOfPiSymbol(FourierCirclesScene):
|
||||||
coefs = self.get_coefficients_of_path(path)
|
coefs = self.get_coefficients_of_path(path)
|
||||||
|
|
||||||
circles = self.get_circles(coefficients=coefs)
|
circles = self.get_circles(coefficients=coefs)
|
||||||
for k, circle in zip(it.count(1), circles):
|
self.set_decreasing_stroke_widths(circles)
|
||||||
circle.set_stroke(width=max(
|
|
||||||
1 / np.sqrt(k),
|
|
||||||
1,
|
|
||||||
))
|
|
||||||
|
|
||||||
# approx_path = self.get_circle_end_path(circles)
|
# approx_path = self.get_circle_end_path(circles)
|
||||||
drawn_path = self.get_drawn_path(circles)
|
drawn_path = self.get_drawn_path(circles)
|
||||||
if self.start_drawn:
|
if self.start_drawn:
|
||||||
|
@ -329,6 +324,14 @@ class FourierOfPiSymbol(FourierCirclesScene):
|
||||||
self.add(drawn_path)
|
self.add(drawn_path)
|
||||||
self.wait(self.run_time)
|
self.wait(self.run_time)
|
||||||
|
|
||||||
|
def set_decreasing_stroke_widths(self, circles):
|
||||||
|
for k, circle in zip(it.count(1), circles):
|
||||||
|
circle.set_stroke(width=max(
|
||||||
|
1 / np.sqrt(k),
|
||||||
|
1,
|
||||||
|
))
|
||||||
|
return circles
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self):
|
||||||
tex_mob = TexMobject(self.tex)
|
tex_mob = TexMobject(self.tex)
|
||||||
tex_mob.set_height(6)
|
tex_mob.set_height(6)
|
||||||
|
@ -338,6 +341,51 @@ class FourierOfPiSymbol(FourierCirclesScene):
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
class FourierOfName(FourierOfPiSymbol):
|
||||||
|
CONFIG = {
|
||||||
|
"n_circles": 100,
|
||||||
|
"name_color": WHITE,
|
||||||
|
"name_text": "Abc",
|
||||||
|
"time_per_symbol": 5,
|
||||||
|
"slow_factor": 1 / 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
def construct(self):
|
||||||
|
name = TextMobject(self.name_text)
|
||||||
|
max_width = FRAME_WIDTH - 2
|
||||||
|
max_height = FRAME_HEIGHT - 2
|
||||||
|
name.set_width(max_width)
|
||||||
|
if name.get_height() > max_height:
|
||||||
|
name.set_height(max_height)
|
||||||
|
|
||||||
|
circles = VGroup(VectorizedPoint())
|
||||||
|
for path in name.family_members_with_points():
|
||||||
|
for subpath in path.get_subpaths():
|
||||||
|
sp_mob = VMobject()
|
||||||
|
sp_mob.set_points(subpath)
|
||||||
|
coefs = self.get_coefficients_of_path(sp_mob)
|
||||||
|
new_circles = self.get_circles(
|
||||||
|
coefficients=coefs
|
||||||
|
)
|
||||||
|
self.set_decreasing_stroke_widths(new_circles)
|
||||||
|
drawn_path = self.get_drawn_path(new_circles)
|
||||||
|
drawn_path.clear_updaters()
|
||||||
|
drawn_path.set_stroke(self.name_color, 3)
|
||||||
|
|
||||||
|
new_circles.suspend_updating()
|
||||||
|
self.play(ReplacementTransform(circles, new_circles))
|
||||||
|
new_circles.resume_updating()
|
||||||
|
circles = new_circles
|
||||||
|
self.play(
|
||||||
|
ShowCreation(drawn_path),
|
||||||
|
rate_func=linear,
|
||||||
|
run_time=self.time_per_symbol
|
||||||
|
)
|
||||||
|
circles.suspend_updating()
|
||||||
|
self.play(FadeOut(circles))
|
||||||
|
self.wait(3)
|
||||||
|
|
||||||
|
|
||||||
class FourierOfPiSymbol5(FourierOfPiSymbol):
|
class FourierOfPiSymbol5(FourierOfPiSymbol):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"n_circles": 5,
|
"n_circles": 5,
|
||||||
|
|
Loading…
Add table
Reference in a new issue