mirror of
https://github.com/3b1b/manim.git
synced 2025-08-01 08:54:38 +08:00
More bell fixes
This commit is contained in:
141
bell.py
141
bell.py
@ -165,10 +165,12 @@ class PhotonPassesCompletelyOrNotAtAll(DirectionOfPolarization):
|
|||||||
"EMWave_config" : {
|
"EMWave_config" : {
|
||||||
"wave_number" : 0,
|
"wave_number" : 0,
|
||||||
"A_vect" : [0, 1, 1],
|
"A_vect" : [0, 1, 1],
|
||||||
|
"start_point" : SPACE_WIDTH*LEFT + DOWN + 1.5*OUT,
|
||||||
},
|
},
|
||||||
"start_theta" : -0.9*np.pi,
|
"start_theta" : -0.9*np.pi,
|
||||||
"target_theta" : -0.6*np.pi,
|
"target_theta" : -0.6*np.pi,
|
||||||
"apply_filter" : True,
|
"apply_filter" : True,
|
||||||
|
"lower_portion_shift" : 3*IN
|
||||||
}
|
}
|
||||||
def setup(self):
|
def setup(self):
|
||||||
DirectionOfPolarization.setup(self)
|
DirectionOfPolarization.setup(self)
|
||||||
@ -179,9 +181,10 @@ class PhotonPassesCompletelyOrNotAtAll(DirectionOfPolarization):
|
|||||||
|
|
||||||
def construct(self):
|
def construct(self):
|
||||||
pol_filter = self.pol_filter
|
pol_filter = self.pol_filter
|
||||||
label = pol_filter.label
|
pol_filter.shift(0.5*OUT)
|
||||||
pol_filter.remove(label)
|
lower_filter = pol_filter.copy()
|
||||||
label.shift(SMALL_BUFF*IN)
|
lower_filter.save_state()
|
||||||
|
pol_filter.remove(pol_filter.label)
|
||||||
|
|
||||||
passing_words = TextMobject("Photon", "passes through")
|
passing_words = TextMobject("Photon", "passes through")
|
||||||
passing_words.highlight(GREEN)
|
passing_words.highlight(GREEN)
|
||||||
@ -192,36 +195,44 @@ class PhotonPassesCompletelyOrNotAtAll(DirectionOfPolarization):
|
|||||||
words.shift(2*UP)
|
words.shift(2*UP)
|
||||||
words.add_background_rectangle()
|
words.add_background_rectangle()
|
||||||
words.rotate(np.pi/2, RIGHT)
|
words.rotate(np.pi/2, RIGHT)
|
||||||
self.continual_update()
|
filtered_words.shift(self.lower_portion_shift)
|
||||||
|
|
||||||
passing_photon = WavePacket(
|
passing_photon = WavePacket(
|
||||||
run_time = 2,
|
run_time = 2,
|
||||||
get_filtered = False,
|
get_filtered = False,
|
||||||
em_wave = self.em_wave.copy()
|
em_wave = self.em_wave.copy()
|
||||||
)
|
)
|
||||||
|
lower_em_wave = self.em_wave.copy()
|
||||||
|
lower_em_wave.mobject.shift(self.lower_portion_shift)
|
||||||
|
lower_em_wave.start_point += self.lower_portion_shift
|
||||||
filtered_photon = WavePacket(
|
filtered_photon = WavePacket(
|
||||||
run_time = 2,
|
run_time = 2,
|
||||||
get_filtered = True,
|
get_filtered = True,
|
||||||
em_wave = self.em_wave.copy()
|
em_wave = lower_em_wave.copy()
|
||||||
)
|
)
|
||||||
|
|
||||||
self.play(
|
self.play(
|
||||||
DrawBorderThenFill(pol_filter),
|
DrawBorderThenFill(pol_filter),
|
||||||
Write(label, run_time = 2)
|
Write(pol_filter.label, run_time = 2)
|
||||||
)
|
)
|
||||||
self.move_camera(theta = self.target_theta)
|
self.move_camera(theta = self.target_theta)
|
||||||
self.play(Write(passing_words, run_time = 1))
|
|
||||||
self.play(passing_photon)
|
|
||||||
self.play(Transform(passing_words, filtered_words))
|
|
||||||
self.play(
|
self.play(
|
||||||
filtered_photon,
|
lower_filter.restore,
|
||||||
ApplyMethod(
|
lower_filter.shift, self.lower_portion_shift,
|
||||||
pol_filter.set_fill, RED,
|
FadeIn(passing_words),
|
||||||
rate_func = squish_rate_func(there_and_back, 0.4, 0.6),
|
FadeIn(filtered_words)
|
||||||
run_time = filtered_photon.run_time
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
self.dither(3)
|
for x in range(3):
|
||||||
|
self.play(
|
||||||
|
passing_photon,
|
||||||
|
filtered_photon,
|
||||||
|
ApplyMethod(
|
||||||
|
lower_filter.set_fill, RED,
|
||||||
|
rate_func = squish_rate_func(there_and_back, 0.4, 0.6),
|
||||||
|
run_time = filtered_photon.run_time
|
||||||
|
)
|
||||||
|
)
|
||||||
|
self.dither()
|
||||||
|
|
||||||
class PhotonsThroughPerpendicularFilters(PhotonPassesCompletelyOrNotAtAll):
|
class PhotonsThroughPerpendicularFilters(PhotonPassesCompletelyOrNotAtAll):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
@ -234,30 +245,40 @@ class PhotonsThroughPerpendicularFilters(PhotonPassesCompletelyOrNotAtAll):
|
|||||||
"target_theta" : -0.6*np.pi,
|
"target_theta" : -0.6*np.pi,
|
||||||
"EMWave_config" : {
|
"EMWave_config" : {
|
||||||
"A_vect" : [0, 0, 1],
|
"A_vect" : [0, 0, 1],
|
||||||
|
"start_point" : SPACE_WIDTH*LEFT + DOWN + OUT,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
def construct(self):
|
def construct(self):
|
||||||
photons = self.get_photons()[:2]
|
photons = self.get_photons()
|
||||||
prob_text = self.get_probability_text()
|
prob_text = self.get_probability_text()
|
||||||
self.pol_filters = VGroup(*reversed(self.pol_filters))
|
self.pol_filters = VGroup(*reversed(self.pol_filters))
|
||||||
|
|
||||||
self.play(LaggedStart(DrawBorderThenFill, self.pol_filters))
|
self.play(LaggedStart(DrawBorderThenFill, self.pol_filters))
|
||||||
|
self.add_foreground_mobject(self.pol_filters)
|
||||||
self.move_camera(
|
self.move_camera(
|
||||||
theta = self.target_theta,
|
theta = self.target_theta,
|
||||||
added_anims = [
|
added_anims = list(it.chain(*[
|
||||||
FadeIn(prob_text)
|
[
|
||||||
]
|
pf.arrow_label.rotate_in_place, np.pi/2, OUT,
|
||||||
|
pf.arrow_label.next_to, pf.arrow, RIGHT,
|
||||||
|
]
|
||||||
|
for pf in self.pol_filters
|
||||||
|
]))
|
||||||
)
|
)
|
||||||
for x in range(4):
|
self.shoot_photon()
|
||||||
pairs = zip(photons, reversed(self.pol_filters))
|
self.dither()
|
||||||
random.shuffle(pairs)
|
self.shoot_photon()
|
||||||
for photon, pol_filter in pairs:
|
self.play(FadeIn(prob_text))
|
||||||
self.play(
|
for x in range(8):
|
||||||
photon,
|
self.shoot_photon()
|
||||||
self.get_filter_absorbtion_animation(
|
|
||||||
pol_filter, photon
|
|
||||||
)
|
def shoot_photon(self, *added_anims):
|
||||||
)
|
photon = self.get_photons()[1]
|
||||||
|
pol_filter = self.pol_filters[0]
|
||||||
|
absorbtion = self.get_filter_absorbtion_animation(pol_filter, photon)
|
||||||
|
self.play(photon, absorbtion)
|
||||||
|
|
||||||
|
|
||||||
def get_photons(self):
|
def get_photons(self):
|
||||||
self.reference_line.rotate(np.pi/4)
|
self.reference_line.rotate(np.pi/4)
|
||||||
@ -310,6 +331,8 @@ class MoreFiltersMoreLight(FilterScene):
|
|||||||
for angle in np.linspace(0, np.pi/2, 5)
|
for angle in np.linspace(0, np.pi/2, 5)
|
||||||
],
|
],
|
||||||
"ambient_rotation_rate" : 0,
|
"ambient_rotation_rate" : 0,
|
||||||
|
"arrow_rgb" : (0, 0, 0),
|
||||||
|
"background_rgb" : (245, 245, 245),
|
||||||
}
|
}
|
||||||
def construct(self):
|
def construct(self):
|
||||||
self.remove(self.axes)
|
self.remove(self.axes)
|
||||||
@ -366,7 +389,7 @@ class MoreFiltersMoreLight(FilterScene):
|
|||||||
self.set_camera_position(np.pi/2, -np.pi)
|
self.set_camera_position(np.pi/2, -np.pi)
|
||||||
|
|
||||||
self.original_rgbs = [(255, 255, 255)]
|
self.original_rgbs = [(255, 255, 255)]
|
||||||
self.new_rgbs = [(255, 255, 255)]
|
self.new_rgbs = [self.arrow_rgb]
|
||||||
for bool_array in it.product(*5*[[True, False]]):
|
for bool_array in it.product(*5*[[True, False]]):
|
||||||
pfs_to_use = VGroup(*[
|
pfs_to_use = VGroup(*[
|
||||||
pf
|
pf
|
||||||
@ -385,12 +408,15 @@ class MoreFiltersMoreLight(FilterScene):
|
|||||||
p *= np.cos(a2 - a1)**2
|
p *= np.cos(a2 - a1)**2
|
||||||
new_rgb = (255*p*np.ones(3)).astype(int)
|
new_rgb = (255*p*np.ones(3)).astype(int)
|
||||||
if not any(bool_array):
|
if not any(bool_array):
|
||||||
new_rgb = [0, 0, 0]
|
new_rgb = self.background_rgb
|
||||||
|
|
||||||
self.new_rgbs.append(new_rgb)
|
self.new_rgbs.append(new_rgb)
|
||||||
self.camera.reset()
|
self.camera.reset()
|
||||||
self.set_camera_position(phi, theta)
|
self.set_camera_position(phi, theta)
|
||||||
|
|
||||||
|
def update_frame(self, mobjects = None, image = None):
|
||||||
|
FilterScene.update_frame(self, mobjects)
|
||||||
|
|
||||||
def get_frame(self):
|
def get_frame(self):
|
||||||
frame = FilterScene.get_frame(self)
|
frame = FilterScene.get_frame(self)
|
||||||
bool_arrays = [
|
bool_arrays = [
|
||||||
@ -406,6 +432,12 @@ class MoreFiltersMoreLight(FilterScene):
|
|||||||
frame[~covered] = [65, 65, 65]
|
frame[~covered] = [65, 65, 65]
|
||||||
return frame
|
return frame
|
||||||
|
|
||||||
|
class MoreFiltersMoreLightBlackBackground(MoreFiltersMoreLight):
|
||||||
|
CONFIG = {
|
||||||
|
"arrow_rgb" : (255, 255, 255),
|
||||||
|
"background_rgb" : (0, 0, 0),
|
||||||
|
}
|
||||||
|
|
||||||
class ConfusedPiCreature(Scene):
|
class ConfusedPiCreature(Scene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
randy = Randolph()
|
randy = Randolph()
|
||||||
@ -432,33 +464,44 @@ class AngryPiCreature(PiCreatureScene):
|
|||||||
|
|
||||||
class ShowALittleMath(TeacherStudentsScene):
|
class ShowALittleMath(TeacherStudentsScene):
|
||||||
def construct(self):
|
def construct(self):
|
||||||
expression = TexMobject(
|
exp1 = TexMobject(
|
||||||
"\\alpha", "| \\! \\uparrow \\rangle", "+",
|
"|", "\\psi", "\\rangle = ",
|
||||||
"\\beta", "| \\! \\rightarrow \\rangle",
|
"\\alpha", "|\\uparrow\\rangle",
|
||||||
|
"+", "\\beta", "|\\rightarrow\\rangle"
|
||||||
)
|
)
|
||||||
expression.highlight_by_tex("uparrow", GREEN)
|
exp2 = TexMobject(
|
||||||
expression.highlight_by_tex("rightarrow", RED)
|
"|| \\langle", "\\psi", "|", "\\psi", "\\rangle ||^2",
|
||||||
expression.next_to(self.teacher, UP+LEFT, LARGE_BUFF)
|
"= ", "\\alpha", "^2", "+", "\\beta", "^2"
|
||||||
|
)
|
||||||
|
color_map = {
|
||||||
|
"alpha" : GREEN,
|
||||||
|
"beta" : RED,
|
||||||
|
"psi" : BLUE
|
||||||
|
}
|
||||||
|
for exp in exp1, exp2:
|
||||||
|
exp.highlight_by_tex_to_color_map(color_map)
|
||||||
|
exp1.next_to(self.teacher.get_corner(UP+LEFT), UP, LARGE_BUFF)
|
||||||
|
|
||||||
prob = TexMobject("\\text{Probability}", "=", "|", "\\alpha", "|^2")
|
exp2.move_to(exp1)
|
||||||
prob.next_to(expression, UP, LARGE_BUFF)
|
|
||||||
|
|
||||||
self.play(
|
self.play(
|
||||||
Write(expression, run_time = 2),
|
Write(exp1, run_time = 2),
|
||||||
self.teacher.change, "raise_right_hand"
|
self.teacher.change, "raise_right_hand"
|
||||||
)
|
)
|
||||||
target_alpha = prob.get_part_by_tex("alpha")
|
self.play(exp1.shift, UP)
|
||||||
prob.remove(target_alpha)
|
|
||||||
self.play(
|
self.play(
|
||||||
ReplacementTransform(
|
Write(exp2, run_time = 2),
|
||||||
expression.get_part_by_tex("alpha").copy(),
|
*[
|
||||||
target_alpha,
|
ReplacementTransform(
|
||||||
),
|
exp1.get_parts_by_tex(tex).copy(),
|
||||||
Write(prob, run_time = 2)
|
exp2.get_parts_by_tex(tex).copy(),
|
||||||
|
)
|
||||||
|
for tex in color_map.keys()
|
||||||
|
]
|
||||||
)
|
)
|
||||||
self.change_student_modes(
|
self.change_student_modes(
|
||||||
*["pondering"]*3,
|
*["pondering"]*3,
|
||||||
look_at_arg = prob
|
look_at_arg = exp2
|
||||||
)
|
)
|
||||||
self.dither(2)
|
self.dither(2)
|
||||||
|
|
||||||
|
@ -91,6 +91,7 @@ class TexMobject(SVGMobject):
|
|||||||
len(tex) > len(t1) and tex[len(t1)] in "()[]\\"
|
len(tex) > len(t1) and tex[len(t1)] in "()[]\\"
|
||||||
])
|
])
|
||||||
if should_replace:
|
if should_replace:
|
||||||
|
print len(t1)
|
||||||
tex = tex.replace(t1, "\\big")
|
tex = tex.replace(t1, "\\big")
|
||||||
if tex == "":
|
if tex == "":
|
||||||
tex = "\\quad"
|
tex = "\\quad"
|
||||||
|
5
waves.py
5
waves.py
@ -264,17 +264,18 @@ class PolarizingFilter(Circle):
|
|||||||
"label_tex" : None,
|
"label_tex" : None,
|
||||||
"filter_angle" : 0,
|
"filter_angle" : 0,
|
||||||
"include_arrow_label" : True,
|
"include_arrow_label" : True,
|
||||||
|
"arrow_length" : 1,
|
||||||
}
|
}
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
Circle.__init__(self, **kwargs)
|
Circle.__init__(self, **kwargs)
|
||||||
|
|
||||||
if self.label_tex:
|
if self.label_tex:
|
||||||
self.label = TexMobject(self.label_tex)
|
self.label = TexMobject(self.label_tex)
|
||||||
self.label.next_to(self.get_top(), DOWN, SMALL_BUFF)
|
self.label.next_to(self.get_top(), DOWN, MED_SMALL_BUFF)
|
||||||
self.add(self.label)
|
self.add(self.label)
|
||||||
|
|
||||||
arrow = Arrow(
|
arrow = Arrow(
|
||||||
ORIGIN, 0.7*UP,
|
ORIGIN, self.arrow_length*UP,
|
||||||
color = WHITE,
|
color = WHITE,
|
||||||
buff = 0,
|
buff = 0,
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user