Began clacks solution animations (just for the recap scenes, so mostly carried over from clacks)

This commit is contained in:
Grant Sanderson 2019-01-12 14:44:26 -08:00
parent ee52eae965
commit c735119367
2 changed files with 106 additions and 9 deletions

View file

@ -3,9 +3,6 @@ import subprocess
from pydub import AudioSegment
MIN_TIME_BETWEEN_FLASHES = 0.004
class SlidingBlocks(VGroup):
CONFIG = {
"block1_config": {
@ -225,6 +222,7 @@ class ClackFlashes(ContinualAnimation):
"flash_radius": 0.2,
},
"start_up_time": 0,
"min_time_between_flashes": 1 / 30,
}
def __init__(self, clack_data, **kwargs):
@ -233,7 +231,7 @@ class ClackFlashes(ContinualAnimation):
group = Group()
last_time = 0
for location, time in clack_data:
if (time - last_time) < MIN_TIME_BETWEEN_FLASHES:
if (time - last_time) < self.min_time_between_flashes:
continue
last_time = time
flash = Flash(location, **self.flash_config)
@ -268,6 +266,7 @@ class BlocksAndWallScene(Scene):
"counter_label": "\\# Collisions: ",
"collision_sound": "clack.wav",
"show_flash_animations": True,
"min_time_between_sounds": 0.004,
}
def setup(self):
@ -359,7 +358,7 @@ class BlocksAndWallScene(Scene):
total_time = max(times) + 1
clacks = AudioSegment.silent(int(1000 * total_time))
last_position = 0
min_diff = int(1000 * MIN_TIME_BETWEEN_FLASHES)
min_diff = int(1000 * self.min_time_between_sounds)
for time in times:
position = int(1000 * time)
d_position = position - last_position

View file

@ -3,9 +3,47 @@ from active_projects.clacks import *
class LastVideo(Scene):
# TODO, add solution image
class FromPuzzleToSolution(MovingCameraScene):
def construct(self):
pass
big_rect = FullScreenFadeRectangle()
big_rect.set_fill(DARK_GREY, 0.5)
self.add(big_rect)
rects = VGroup(ScreenRectangle(), ScreenRectangle())
rects.set_height(3)
rects.arrange_submobjects(RIGHT, buff=2)
titles = VGroup(
TextMobject("Puzzle"),
TextMobject("Solution"),
)
images = Group(
ImageMobject("BlocksAndWallExampleMass16"),
ImageMobject("SphereSurfaceProof2"), # TODO
)
for title, rect, image in zip(titles, rects, images):
title.scale(1.5)
title.next_to(rect, UP)
image.replace(rect)
self.add(image, rect, title)
frame = self.camera_frame
frame.save_state()
self.play(
frame.replace, images[0],
run_time=3
)
self.wait()
self.play(Restore(frame, run_time=3))
self.play(
frame.replace, images[1],
run_time=3,
)
self.wait()
class BlocksAndWallExampleMass16(BlocksAndWallExample):
@ -20,7 +58,6 @@ class BlocksAndWallExampleMass16(BlocksAndWallExample):
}
class Mass16WithElasticLabel(Mass1e1WithElasticLabel):
CONFIG = {
"sliding_blocks_config": {
@ -40,4 +77,65 @@ class BlocksAndWallExampleMass64(BlocksAndWallExample):
},
},
"wait_time": 25,
}
}
class BlocksAndWallExampleMass1e4(BlocksAndWallExample):
CONFIG = {
"sliding_blocks_config": {
"block1_config": {
"mass": 64,
"velocity": -1.5,
},
},
"wait_time": 25,
}
class BlocksAndWallExampleMassMillion(BlocksAndWallExample):
CONFIG = {
"sliding_blocks_config": {
"block1_config": {
"mass": 1e6,
"velocity": -0.9,
"label_text": "$100^{3}$ kg"
},
},
"wait_time": 30,
"million_fade_time": 4,
"min_time_between_sounds": 0.002,
}
def setup(self):
super().setup()
self.add_million_label()
def add_million_label(self):
first_label = self.blocks.block1.label
brace = Brace(first_label[:-2], UP, buff=SMALL_BUFF)
new_label = TexMobject("1{,}000{,}000")
new_label.next_to(brace, UP, buff=SMALL_BUFF)
new_label.add(brace)
new_label.set_color(YELLOW)
def update_label(label):
d_time = self.get_time() - self.million_fade_time
opacity = smooth(d_time)
label.set_fill(opacity=d_time)
new_label.add_updater(update_label)
first_label.add(new_label)
class BlocksAndWallExampleMassTrillion(BlocksAndWallExample):
CONFIG = {
"sliding_blocks_config": {
"block1_config": {
"mass": 1e12,
"velocity": -1,
},
},
"wait_time": 30,
"min_time_between_sounds": 0.001,
}