mirror of
https://github.com/3b1b/manim.git
synced 2025-08-05 16:49:03 +00:00
Smattering of Bell and Wave work
This commit is contained in:
parent
b88c669627
commit
12dcb7a3ea
6 changed files with 1016 additions and 138 deletions
107
bell.py
107
bell.py
|
@ -443,24 +443,6 @@ class BasicsOfPolarization(DirectionOfPolarizationScene):
|
||||||
self.show_continual_wave()
|
self.show_continual_wave()
|
||||||
self.show_photons()
|
self.show_photons()
|
||||||
|
|
||||||
def setup_rectangles(self):
|
|
||||||
rect1 = Rectangle(
|
|
||||||
height = 2*self.em_wave.amplitude,
|
|
||||||
width = SPACE_WIDTH + 0.25,
|
|
||||||
stroke_color = BLUE,
|
|
||||||
fill_color = BLUE,
|
|
||||||
fill_opacity = 0.2,
|
|
||||||
)
|
|
||||||
rect1.rotate(np.pi/2, RIGHT)
|
|
||||||
pf_copy = self.pol_filter.deepcopy()
|
|
||||||
pf_copy.remove(pf_copy.arrow)
|
|
||||||
center = pf_copy.get_center()
|
|
||||||
rect1.move_to(center, RIGHT)
|
|
||||||
rect2 = rect1.copy()
|
|
||||||
rect2.move_to(center, LEFT)
|
|
||||||
|
|
||||||
self.rectangles = VGroup(rect1, rect2)
|
|
||||||
|
|
||||||
def show_continual_wave(self):
|
def show_continual_wave(self):
|
||||||
em_wave = self.em_wave
|
em_wave = self.em_wave
|
||||||
|
|
||||||
|
@ -567,27 +549,6 @@ class BasicsOfPolarization(DirectionOfPolarizationScene):
|
||||||
for index in 1, 0, 0, 1:
|
for index in 1, 0, 0, 1:
|
||||||
self.play(*anim_sets[index])
|
self.play(*anim_sets[index])
|
||||||
|
|
||||||
def continual_update(self, *args, **kwargs):
|
|
||||||
DirectionOfPolarizationScene.continual_update(self, *args, **kwargs)
|
|
||||||
if self.rectangles not in self.mobjects:
|
|
||||||
return
|
|
||||||
|
|
||||||
r1, r2 = self.rectangles
|
|
||||||
|
|
||||||
target_angle = self.reference_line.get_angle()
|
|
||||||
anchors = r1.get_anchors()
|
|
||||||
vect = anchors[0] - anchors[3]
|
|
||||||
curr_angle = angle_of_vector([vect[2], -vect[1]])
|
|
||||||
r1.rotate_in_place(target_angle - curr_angle, RIGHT)
|
|
||||||
|
|
||||||
epsilon = 0.001
|
|
||||||
curr_depth = max(r2.get_depth(), epsilon)
|
|
||||||
target_depth = max(
|
|
||||||
2*self.em_wave.amplitude*np.cos(target_angle),
|
|
||||||
epsilon
|
|
||||||
)
|
|
||||||
r2.stretch_in_place(target_depth/curr_depth, 2)
|
|
||||||
|
|
||||||
class AngleToProbabilityChart(Scene):
|
class AngleToProbabilityChart(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
left_title = TextMobject("Angle between \\\\ filters")
|
left_title = TextMobject("Angle between \\\\ filters")
|
||||||
|
@ -1748,6 +1709,10 @@ class VennDiagramProofByContradiction(Scene):
|
||||||
C_copy = C.copy()
|
C_copy = C.copy()
|
||||||
C_copy.set_fill(BLACK, opacity = 1)
|
C_copy.set_fill(BLACK, opacity = 1)
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
self.in_A_in_B.set_fill, GREEN, 0.5,
|
||||||
|
rate_func = there_and_back,
|
||||||
|
)
|
||||||
self.play(
|
self.play(
|
||||||
MoveToTarget(C),
|
MoveToTarget(C),
|
||||||
MoveToTarget(C.label),
|
MoveToTarget(C.label),
|
||||||
|
@ -1761,7 +1726,6 @@ class VennDiagramProofByContradiction(Scene):
|
||||||
ShowCreation(arrow),
|
ShowCreation(arrow),
|
||||||
Animation(out_of_C),
|
Animation(out_of_C),
|
||||||
)
|
)
|
||||||
self.dither()
|
|
||||||
self.play(ApplyMethod(
|
self.play(ApplyMethod(
|
||||||
VGroup(self.in_A_in_B_out_C, out_of_C).shift,
|
VGroup(self.in_A_in_B_out_C, out_of_C).shift,
|
||||||
MED_LARGE_BUFF*UP,
|
MED_LARGE_BUFF*UP,
|
||||||
|
@ -1815,7 +1779,8 @@ class VennDiagramProofByContradiction(Scene):
|
||||||
terms.to_edge(UP)
|
terms.to_edge(UP)
|
||||||
for term, index, group in zip(terms, [-3, -2, -2], photon_groups):
|
for term, index, group in zip(terms, [-3, -2, -2], photon_groups):
|
||||||
term.highlight_by_tex("checkmark", "#00ff00")
|
term.highlight_by_tex("checkmark", "#00ff00")
|
||||||
cross = Cross(term[index], color = "#ff0000")
|
cross = Cross(term[index])
|
||||||
|
cross.highlight("#ff0000")
|
||||||
cross.set_stroke(width = 8)
|
cross.set_stroke(width = 8)
|
||||||
term[index].add(cross)
|
term[index].add(cross)
|
||||||
|
|
||||||
|
@ -1848,6 +1813,13 @@ class VennDiagramProofByContradiction(Scene):
|
||||||
cross.highlight("#ff0000")
|
cross.highlight("#ff0000")
|
||||||
cross.set_stroke(width = 8)
|
cross.set_stroke(width = 8)
|
||||||
|
|
||||||
|
tweaser_group = VGroup(
|
||||||
|
self.in_A_in_B_out_C.copy(),
|
||||||
|
self.in_A_out_B.copy(),
|
||||||
|
)
|
||||||
|
tweaser_group.set_fill(TEAL, 1)
|
||||||
|
tweaser_group.set_stroke(TEAL, 5)
|
||||||
|
|
||||||
#Fade out B circle
|
#Fade out B circle
|
||||||
faders = VGroup(
|
faders = VGroup(
|
||||||
B, B.label,
|
B, B.label,
|
||||||
|
@ -1856,12 +1828,13 @@ class VennDiagramProofByContradiction(Scene):
|
||||||
*regions[1:]
|
*regions[1:]
|
||||||
)
|
)
|
||||||
faders.save_state()
|
faders.save_state()
|
||||||
regions[0].set_stroke(YELLOW, width = 8)
|
|
||||||
regions[0].set_fill(YELLOW, opacity = 0.25)
|
|
||||||
|
|
||||||
self.play(faders.fade, 1)
|
self.play(faders.fade, 1)
|
||||||
self.play(Write(terms[0]), run_time = 1)
|
self.play(Write(terms[0]), run_time = 1)
|
||||||
self.dither()
|
self.dither()
|
||||||
|
self.photon_thinks_in_A_out_C()
|
||||||
|
regions[0].set_stroke(YELLOW, width = 8)
|
||||||
|
regions[0].set_fill(YELLOW, opacity = 0.25)
|
||||||
self.play(
|
self.play(
|
||||||
VGroup(regions[0], all_out_of_C).shift, 0.5*UP,
|
VGroup(regions[0], all_out_of_C).shift, 0.5*UP,
|
||||||
run_time = 1.5,
|
run_time = 1.5,
|
||||||
|
@ -1930,7 +1903,21 @@ class VennDiagramProofByContradiction(Scene):
|
||||||
)
|
)
|
||||||
self.dither()
|
self.dither()
|
||||||
self.play(Transform(rects[0], last_rects))
|
self.play(Transform(rects[0], last_rects))
|
||||||
self.play(FadeOut(rects[0]))
|
self.in_A_out_B.save_state()
|
||||||
|
self.in_A_in_B_out_C.save_state()
|
||||||
|
self.play(
|
||||||
|
self.in_A_out_B.set_fill, YELLOW, 0.5,
|
||||||
|
self.in_A_in_B_out_C.set_fill, YELLOW, 0.5,
|
||||||
|
Animation(self.photons)
|
||||||
|
)
|
||||||
|
self.dither()
|
||||||
|
self.play(
|
||||||
|
FadeOut(rects[0]),
|
||||||
|
self.in_A_out_B.restore,
|
||||||
|
self.in_A_in_B_out_C.restore,
|
||||||
|
Animation(self.in_A_out_C),
|
||||||
|
Animation(self.photons)
|
||||||
|
)
|
||||||
self.dither()
|
self.dither()
|
||||||
self.play(
|
self.play(
|
||||||
FadeIn(should_be_50[1]),
|
FadeIn(should_be_50[1]),
|
||||||
|
@ -1965,6 +1952,38 @@ class VennDiagramProofByContradiction(Scene):
|
||||||
lag_ratio = 0.3
|
lag_ratio = 0.3
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def photon_thinks_in_A_out_C(self):
|
||||||
|
photon = self.photons[-1]
|
||||||
|
photon.save_state()
|
||||||
|
photon.generate_target()
|
||||||
|
photon.target.scale(4)
|
||||||
|
photon.target.center().to_edge(LEFT).shift(DOWN)
|
||||||
|
bubble = ThoughtBubble()
|
||||||
|
content = TexMobject("A", "\\checkmark", ",", "C")
|
||||||
|
content.highlight_by_tex("checkmark", "#00ff00")
|
||||||
|
cross = Cross(content[-1])
|
||||||
|
cross.highlight("#ff0000")
|
||||||
|
content.add(cross)
|
||||||
|
bubble.add_content(content)
|
||||||
|
bubble.resize_to_content()
|
||||||
|
bubble.add(bubble.content)
|
||||||
|
bubble.pin_to(photon.target).shift(SMALL_BUFF*RIGHT)
|
||||||
|
bubble.save_state()
|
||||||
|
bubble.scale(0.25)
|
||||||
|
bubble.move_to(photon.get_corner(UP+RIGHT), DOWN+LEFT)
|
||||||
|
bubble.fade()
|
||||||
|
|
||||||
|
self.play(
|
||||||
|
MoveToTarget(photon),
|
||||||
|
bubble.restore,
|
||||||
|
)
|
||||||
|
self.play(photon.eyes.blink_anim())
|
||||||
|
self.play(
|
||||||
|
photon.restore,
|
||||||
|
FadeOut(bubble)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
#######
|
#######
|
||||||
|
|
||||||
def setup_venn_diagram_sections(self):
|
def setup_venn_diagram_sections(self):
|
||||||
|
|
|
@ -338,6 +338,9 @@ class Mobject(object):
|
||||||
def scale_to_fit_height(self, height):
|
def scale_to_fit_height(self, height):
|
||||||
return self.rescale_to_fit(height, 1, stretch = False)
|
return self.rescale_to_fit(height, 1, stretch = False)
|
||||||
|
|
||||||
|
def scale_to_fit_depth(self, depth):
|
||||||
|
return self.rescale_to_fit(depth, 2, stretch = False)
|
||||||
|
|
||||||
def space_out_submobjects(self, factor = 1.5, **kwargs):
|
def space_out_submobjects(self, factor = 1.5, **kwargs):
|
||||||
self.scale_in_place(factor)
|
self.scale_in_place(factor)
|
||||||
for submob in self.submobjects:
|
for submob in self.submobjects:
|
||||||
|
|
|
@ -84,8 +84,15 @@ class VMobject(Mobject):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def fade(self, darkness = 0.5):
|
def fade(self, darkness = 0.5):
|
||||||
self.set_stroke(width = (1-darkness)*self.get_stroke_width())
|
for submob in self.submobject_family():
|
||||||
self.set_fill(opacity = (1-darkness))
|
submob.set_stroke(
|
||||||
|
width = (1-darkness)*submob.get_stroke_width(),
|
||||||
|
family = False
|
||||||
|
)
|
||||||
|
submob.set_fill(
|
||||||
|
opacity = (1-darkness),
|
||||||
|
family = False
|
||||||
|
)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_fill_color(self):
|
def get_fill_color(self):
|
||||||
|
|
|
@ -152,34 +152,34 @@ class Line(VMobject):
|
||||||
self.generate_points()
|
self.generate_points()
|
||||||
return
|
return
|
||||||
|
|
||||||
# target_vect = np.array(new_end) - np.array(new_start)
|
def put_start_and_end_on_with_projection(self, new_start, new_end):
|
||||||
# curr_vect = self.get_vector()
|
target_vect = np.array(new_end) - np.array(new_start)
|
||||||
# curr_norm = np.linalg.norm(curr_vect)
|
curr_vect = self.get_vector()
|
||||||
# if curr_norm == 0:
|
curr_norm = np.linalg.norm(curr_vect)
|
||||||
# self.generate_points()
|
if curr_norm == 0:
|
||||||
# curr_vect = self.get_vector()
|
self.put_start_and_end_on(new_start, new_end)
|
||||||
# curr_norm = np.linalg.norm(curr_vect)
|
return
|
||||||
# target_norm = np.linalg.norm(target_vect)
|
target_norm = np.linalg.norm(target_vect)
|
||||||
# if target_norm == 0:
|
if target_norm == 0:
|
||||||
# epsilon = 0.001
|
epsilon = 0.001
|
||||||
# self.scale(epsilon/curr_norm)
|
self.scale(epsilon/curr_norm)
|
||||||
# self.move_to(new_start)
|
self.move_to(new_start)
|
||||||
# return
|
return
|
||||||
# unit_target = target_vect / target_norm
|
unit_target = target_vect / target_norm
|
||||||
# unit_curr = curr_vect / curr_norm
|
unit_curr = curr_vect / curr_norm
|
||||||
# normal = np.cross(unit_target, unit_curr)
|
normal = np.cross(unit_target, unit_curr)
|
||||||
# if np.linalg.norm(normal) == 0:
|
if np.linalg.norm(normal) == 0:
|
||||||
# if unit_curr[0] == 0 and unit_curr[1] == 0:
|
if unit_curr[0] == 0 and unit_curr[1] == 0:
|
||||||
# normal = UP
|
normal = UP
|
||||||
# else:
|
else:
|
||||||
# normal = OUT
|
normal = OUT
|
||||||
# angle_diff = np.arccos(
|
angle_diff = np.arccos(
|
||||||
# np.clip(np.dot(unit_target, unit_curr), -1, 1)
|
np.clip(np.dot(unit_target, unit_curr), -1, 1)
|
||||||
# )
|
)
|
||||||
# self.scale(target_norm/curr_norm)
|
self.scale(target_norm/curr_norm)
|
||||||
# self.rotate(-angle_diff, normal)
|
self.rotate(-angle_diff, normal)
|
||||||
# self.shift(new_start - self.get_start())
|
self.shift(new_start - self.get_start())
|
||||||
# return self
|
return self
|
||||||
|
|
||||||
class DashedLine(Line):
|
class DashedLine(Line):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
|
@ -197,10 +197,12 @@ class DashedLine(Line):
|
||||||
for alpha in np.linspace(0, 1, num_interp_points)
|
for alpha in np.linspace(0, 1, num_interp_points)
|
||||||
]
|
]
|
||||||
includes = it.cycle([True, False])
|
includes = it.cycle([True, False])
|
||||||
for p1, p2, include in zip(points, points[1:], includes):
|
self.submobjects = [
|
||||||
if include:
|
Line(p1, p2, **self.init_kwargs)
|
||||||
self.add(Line(p1, p2, **self.init_kwargs))
|
for p1, p2, include in zip(points, points[1:], includes)
|
||||||
self.put_start_and_end_on(self.start, self.end)
|
if include
|
||||||
|
]
|
||||||
|
self.put_start_and_end_on_with_projection(self.start, self.end)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def get_start(self):
|
def get_start(self):
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from mobject.vectorized_mobject import VMobject, VGroup, VectorizedPoint
|
from mobject.vectorized_mobject import VMobject, VGroup, VectorizedPoint
|
||||||
from mobject.tex_mobject import TexMobject
|
from mobject.tex_mobject import TexMobject
|
||||||
from animation import Animation
|
from animation import Animation
|
||||||
|
from animation.continual_animation import ContinualAnimation
|
||||||
from scene import Scene
|
from scene import Scene
|
||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
|
@ -84,7 +85,17 @@ class ChangingDecimal(Animation):
|
||||||
elif self.tracked_mobject is not None:
|
elif self.tracked_mobject is not None:
|
||||||
self.decimal_number.move_to(self.tracked_mobject)
|
self.decimal_number.move_to(self.tracked_mobject)
|
||||||
|
|
||||||
|
class ContinualChangingDecimal(ContinualAnimation):
|
||||||
|
def __init__(self, decimal_number, number_update_func, **kwargs):
|
||||||
|
self.anim = ChangingDecimal(decimal_number, number_update_func, **kwargs)
|
||||||
|
ContinualAnimation.__init__(self, decimal_number, **kwargs)
|
||||||
|
|
||||||
|
def update_mobject(self, dt):
|
||||||
|
self.anim.update(self.internal_time)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue