mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Added clacks_names.py animatiosn
This commit is contained in:
parent
561e2c7a21
commit
77f0ca1ad7
2 changed files with 95 additions and 4 deletions
|
@ -27,6 +27,8 @@ class Block(Square):
|
||||||
self.fill_color = self.mass_to_color(self.mass)
|
self.fill_color = self.mass_to_color(self.mass)
|
||||||
if self.label_text is None:
|
if self.label_text is None:
|
||||||
self.label_text = self.mass_to_label_text(self.mass)
|
self.label_text = self.mass_to_label_text(self.mass)
|
||||||
|
if "width" in kwargs:
|
||||||
|
kwargs.pop("width")
|
||||||
Square.__init__(self, side_length=self.width, **kwargs)
|
Square.__init__(self, side_length=self.width, **kwargs)
|
||||||
self.label = self.get_label()
|
self.label = self.get_label()
|
||||||
self.add(self.label)
|
self.add(self.label)
|
||||||
|
@ -130,8 +132,8 @@ class SlidingBlocks(VGroup):
|
||||||
|
|
||||||
def update_blocks_from_phase_space_point_tracker(self):
|
def update_blocks_from_phase_space_point_tracker(self):
|
||||||
block1, block2 = self.block1, self.block2
|
block1, block2 = self.block1, self.block2
|
||||||
|
|
||||||
ps_point = self.phase_space_point_tracker.get_location()
|
ps_point = self.phase_space_point_tracker.get_location()
|
||||||
|
|
||||||
theta = np.arctan(np.sqrt(self.mass_ratio))
|
theta = np.arctan(np.sqrt(self.mass_ratio))
|
||||||
ps_point_angle = angle_of_vector(ps_point)
|
ps_point_angle = angle_of_vector(ps_point)
|
||||||
n_clacks = int(ps_point_angle / theta)
|
n_clacks = int(ps_point_angle / theta)
|
||||||
|
@ -274,7 +276,6 @@ class BlocksAndWallScene(Scene):
|
||||||
"collision_sound": "clack.wav",
|
"collision_sound": "clack.wav",
|
||||||
"show_flash_animations": True,
|
"show_flash_animations": True,
|
||||||
"min_time_between_sounds": 0.004,
|
"min_time_between_sounds": 0.004,
|
||||||
"allow_sound": True,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
|
@ -1560,7 +1561,7 @@ class EndScreen(Scene):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Thumbnail(BlocksAndWallExample):
|
class Thumbnail(BlocksAndWallExample, MovingCameraScene):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"sliding_blocks_config": {
|
"sliding_blocks_config": {
|
||||||
"block1_config": {
|
"block1_config": {
|
||||||
|
@ -1572,10 +1573,15 @@ class Thumbnail(BlocksAndWallExample):
|
||||||
"wait_time": 0,
|
"wait_time": 0,
|
||||||
"count_clacks": False,
|
"count_clacks": False,
|
||||||
"show_flash_animations": False,
|
"show_flash_animations": False,
|
||||||
"floor_y": -3,
|
"floor_y": -3.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
MovingCameraScene.setup(self)
|
||||||
|
BlocksAndWallExample.setup(self)
|
||||||
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
|
self.camera_frame.shift(0.9 * UP)
|
||||||
self.thicken_lines()
|
self.thicken_lines()
|
||||||
self.grow_labels()
|
self.grow_labels()
|
||||||
self.add_vector()
|
self.add_vector()
|
||||||
|
|
85
active_projects/clacks_names.py
Normal file
85
active_projects/clacks_names.py
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
from big_ol_pile_of_manim_imports import *
|
||||||
|
|
||||||
|
from active_projects.clacks import BlocksAndWallExample
|
||||||
|
|
||||||
|
|
||||||
|
class NameBump(BlocksAndWallExample):
|
||||||
|
CONFIG = {
|
||||||
|
"name": "Magnus Lysfjord",
|
||||||
|
"sliding_blocks_config": {
|
||||||
|
"block1_config": {
|
||||||
|
"mass": 1e6,
|
||||||
|
"velocity": -0.5,
|
||||||
|
"distance": 7,
|
||||||
|
},
|
||||||
|
"block2_config": {},
|
||||||
|
},
|
||||||
|
"wait_time": 25,
|
||||||
|
}
|
||||||
|
|
||||||
|
def setup(self):
|
||||||
|
names = self.name.split(" ")
|
||||||
|
n = len(names)
|
||||||
|
if n == 1:
|
||||||
|
names = 2 * [names[0]]
|
||||||
|
elif n > 2:
|
||||||
|
names = [
|
||||||
|
" ".join(names[:n // 2]),
|
||||||
|
" ".join(names[n // 2:]),
|
||||||
|
]
|
||||||
|
# Swap, to show first name on the left
|
||||||
|
names = [names[1], names[0]]
|
||||||
|
|
||||||
|
name_mobs = VGroup(*map(TextMobject, names))
|
||||||
|
name_mobs.set_stroke(BLACK, 3, background=True)
|
||||||
|
name_mobs.set_fill(LIGHT_GREY, 1)
|
||||||
|
name_mobs.set_sheen(3, UL)
|
||||||
|
name_mobs.scale(2)
|
||||||
|
configs = [
|
||||||
|
self.sliding_blocks_config["block1_config"],
|
||||||
|
self.sliding_blocks_config["block2_config"],
|
||||||
|
]
|
||||||
|
for name_mob, config in zip(name_mobs, configs):
|
||||||
|
config["width"] = name_mob.get_width()
|
||||||
|
self.name_mobs = name_mobs
|
||||||
|
|
||||||
|
super().setup()
|
||||||
|
|
||||||
|
def add_blocks(self):
|
||||||
|
super().add_blocks()
|
||||||
|
blocks = self.blocks
|
||||||
|
name_mobs = self.name_mobs
|
||||||
|
|
||||||
|
blocks.fade(1)
|
||||||
|
|
||||||
|
def update_name_mobs(name_mobs):
|
||||||
|
for name_mob, block in zip(name_mobs, self.blocks):
|
||||||
|
name_mob.move_to(block)
|
||||||
|
target_y = block.get_bottom()[1] + SMALL_BUFF
|
||||||
|
curr_y = name_mob[0].get_bottom()[1]
|
||||||
|
name_mob.shift((target_y - curr_y) * UP)
|
||||||
|
|
||||||
|
name_mobs.add_updater(update_name_mobs)
|
||||||
|
self.add(name_mobs)
|
||||||
|
|
||||||
|
clack_y = self.name_mobs[1].get_center()[1]
|
||||||
|
for location, time in self.clack_data:
|
||||||
|
location[1] = clack_y
|
||||||
|
|
||||||
|
for block, name_mob in zip(blocks, name_mobs):
|
||||||
|
block.label.next_to(name_mob, UP)
|
||||||
|
block.label.set_fill(YELLOW, opacity=1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# for name in names:
|
||||||
|
# file_name = name.replace(".", "")
|
||||||
|
# file_name += " Name Bump"
|
||||||
|
# scene = NameBump(
|
||||||
|
# name=name,
|
||||||
|
# write_to_movie=True,
|
||||||
|
# output_file_name=file_name,
|
||||||
|
# camera_config=PRODUCTION_QUALITY_CAMERA_CONFIG,
|
||||||
|
# frame_duration=PRODUCTION_QUALITY_FRAME_DURATION,
|
||||||
|
# )
|
Loading…
Add table
Reference in a new issue