mirror of
https://github.com/3b1b/videos.git
synced 2025-09-18 21:38:53 +00:00
Various thumbnail changes
This commit is contained in:
parent
33609fb7b0
commit
17e38e03dc
8 changed files with 296 additions and 71 deletions
|
@ -1,5 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from constants import *
|
||||
import scipy.integrate
|
||||
|
||||
from manim_imports_ext import *
|
||||
|
@ -57,6 +56,11 @@ def get_fourier_transform(
|
|||
return complex_to_real_func(z)
|
||||
return fourier_transform
|
||||
|
||||
|
||||
class TODOStub(Scene):
|
||||
def construct(self):
|
||||
pass
|
||||
|
||||
##
|
||||
|
||||
class Introduction(TeacherStudentsScene):
|
||||
|
@ -4237,43 +4241,57 @@ class Thumbnail(Scene):
|
|||
return np.cos(2*TAU*t) + np.cos(3*TAU*t) + np.cos(5*t)
|
||||
fourier = get_fourier_transform(func, -5, 5)
|
||||
|
||||
graph = FunctionGraph(func, x_min = -5, x_max = 5)
|
||||
graph = FunctionGraph(func, (-5, 5, 0.01))
|
||||
graph.set_color(BLUE)
|
||||
fourier_graph = FunctionGraph(fourier, x_min = 0, x_max = 6)
|
||||
fourier_graph = FunctionGraph(fourier, (0, 6, 0.01))
|
||||
fourier_graph.set_color(YELLOW)
|
||||
for g in graph, fourier_graph:
|
||||
g.stretch_to_fit_height(2)
|
||||
g.stretch_to_fit_width(10)
|
||||
g.set_stroke(width = 8)
|
||||
g.set_stroke(width=6)
|
||||
|
||||
pol_graphs = VGroup()
|
||||
for f in np.linspace(1.98, 2.02, 7):
|
||||
for f in np.linspace(1.98, 2.02, 5):
|
||||
pol_graph = ParametricCurve(
|
||||
lambda t : complex_to_R3(
|
||||
(2+np.cos(2*TAU*t)+np.cos(3*TAU*t))*np.exp(-complex(0, TAU*f*t))
|
||||
),
|
||||
t_min = -5,
|
||||
t_max = 5,
|
||||
num_graph_points = 200,
|
||||
t_range=(-5, 5, 0.01),
|
||||
)
|
||||
pol_graph.match_color(graph)
|
||||
pol_graph.set_height(2)
|
||||
pol_graphs.add(pol_graph)
|
||||
pol_graphs.arrange(RIGHT, buff = LARGE_BUFF)
|
||||
pol_graphs.set_color_by_gradient(BLUE_C, YELLOW)
|
||||
pol_graphs.arrange(RIGHT, buff=LARGE_BUFF)
|
||||
pol_graphs.set_color_by_gradient(BLUE_C, TEAL, GREEN)
|
||||
pol_graphs.match_width(graph)
|
||||
pol_graphs.set_stroke(width = 2)
|
||||
pol_graphs.set_stroke(width=1)
|
||||
|
||||
parts = VGroup(graph, pol_graphs, fourier_graph)
|
||||
parts[1].set_width(parts[0].get_width() - 1)
|
||||
parts.arrange(
|
||||
DOWN, buff=LARGE_BUFF,
|
||||
aligned_edge=RIGHT
|
||||
)
|
||||
parts.to_edge(RIGHT)
|
||||
self.add(parts)
|
||||
|
||||
self.clear()
|
||||
title.center().to_edge(UP)
|
||||
pol_graphs.set_width(FRAME_WIDTH - 1)
|
||||
pol_graphs.center()
|
||||
title.move_to(pol_graphs)
|
||||
title.shift(SMALL_BUFF*LEFT)
|
||||
graph.next_to(title, UP)
|
||||
fourier_graph.next_to(title, DOWN)
|
||||
self.add(pol_graphs, title, graph, fourier_graph)
|
||||
words = VGroup(TexText("Signal"), TexText("Winding"), TexText("Transform"))
|
||||
for word, part in zip(words, parts):
|
||||
word.scale(1.5)
|
||||
word.next_to(part, LEFT)
|
||||
word.to_edge(LEFT, MED_LARGE_BUFF)
|
||||
|
||||
self.add(words)
|
||||
|
||||
rect = SurroundingRectangle(pol_graphs[2])
|
||||
rect.set_stroke(RED, 2)
|
||||
dot = Dot(fourier_graph.pfp(2 / 6), color=RED)
|
||||
dot.set_stroke(BLACK, 3, background=True)
|
||||
dot.shift(0.01 * RIGHT)
|
||||
line = Line(dot.get_center(), rect.get_corner(DL), buff=0.1)
|
||||
line.match_style(rect)
|
||||
|
||||
self.add(dot, line, rect)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -371,7 +371,7 @@ class FourierOfPiSymbol(FourierCirclesScene):
|
|||
return path
|
||||
|
||||
|
||||
class FourierOfTexPaths(FourierOfPiSymbol, MovingCameraScene):
|
||||
class FourierOfTexPaths(FourierOfPiSymbol):
|
||||
CONFIG = {
|
||||
"n_vectors": 100,
|
||||
"name_color": WHITE,
|
||||
|
|
|
@ -1833,51 +1833,52 @@ class DE4Thumbnail(ComplexFourierSeriesExample):
|
|||
}
|
||||
|
||||
def construct(self):
|
||||
name = TexText("Fourier series")
|
||||
name.set_width(FRAME_WIDTH - 2)
|
||||
name.to_edge(UP)
|
||||
name.set_color(YELLOW)
|
||||
subname = TexText("a.k.a ``everything is rotations''")
|
||||
subname.match_width(name)
|
||||
subname.next_to(name, DOWN)
|
||||
VGroup(name, subname).to_edge(DOWN)
|
||||
|
||||
self.add(name)
|
||||
self.add(subname)
|
||||
|
||||
path = self.get_path()
|
||||
path.to_edge(DOWN)
|
||||
path.set_stroke(YELLOW, 2)
|
||||
freqs = self.get_freqs()
|
||||
coefs = self.get_coefficients_of_path(path, freqs=freqs)
|
||||
vectors = self.get_rotating_vectors(freqs, coefs)
|
||||
# circles = self.get_circles(vectors)
|
||||
circles = self.get_circles(vectors)
|
||||
|
||||
ns = [10, 50, 250]
|
||||
approxs = VGroup(*[
|
||||
self.get_vector_sum_path(vectors[:n])
|
||||
for n in ns
|
||||
])
|
||||
approxs.arrange(RIGHT, buff=2.5)
|
||||
approxs.set_height(3.75)
|
||||
approxs.to_edge(UP, buff=1.25)
|
||||
approxs.arrange(RIGHT, buff=1.0)
|
||||
approxs.set_width(FRAME_WIDTH - 2)
|
||||
approxs.set_y(-0.5)
|
||||
for a, c, w in zip(approxs, [BLUE, GREEN, YELLOW], [4, 3, 2]):
|
||||
a.set_stroke(c, w)
|
||||
a.set_stroke(WHITE, w + w / 2, background=True)
|
||||
a.set_stroke(c, w + w / 2, background=True)
|
||||
|
||||
labels = VGroup()
|
||||
for n, approx in zip(ns, approxs):
|
||||
label = Tex("n = ", str(n))
|
||||
label[1].match_color(approx)
|
||||
label.scale(2)
|
||||
label.next_to(approx, UP)
|
||||
label.to_edge(UP, buff=MED_SMALL_BUFF)
|
||||
label.next_to(approx, UP, MED_LARGE_BUFF)
|
||||
label.shift_onto_screen()
|
||||
labels.add(label)
|
||||
for label in labels:
|
||||
label.align_to(labels[-1], DOWN)
|
||||
|
||||
self.add(approxs)
|
||||
self.add(labels)
|
||||
|
||||
return
|
||||
# Old
|
||||
name = TexText("Fourier series")
|
||||
name.to_edge(UP)
|
||||
name.set_color(YELLOW)
|
||||
subname = TexText("a.k.a ``everything is rotations''")
|
||||
subname.match_width(name)
|
||||
subname.next_to(name, DOWN, SMALL_BUFF)
|
||||
|
||||
names = VGroup(name, subname)
|
||||
names.set_width(8)
|
||||
names.to_edge(DOWN, buff=MED_SMALL_BUFF)
|
||||
|
||||
self.add_vectors_circles_path()
|
||||
n = 6
|
||||
|
|
|
@ -1520,20 +1520,21 @@ class VideoWrapper(Scene):
|
|||
class Thumbnail(Scene):
|
||||
def construct(self):
|
||||
epii = Tex(
|
||||
"e^{{i} \\pi} = -1",
|
||||
"e^{ {i} \\pi} = -1",
|
||||
tex_to_color_map={
|
||||
"{i}": CONST_COLOR,
|
||||
"\\pi": T_COLOR,
|
||||
"-1": POSITION_COLOR,
|
||||
"{i}": YELLOW,
|
||||
"\\pi": BLUE,
|
||||
"-1": GREY_A,
|
||||
}
|
||||
)
|
||||
epii.set_width(8)
|
||||
epii.to_edge(UP)
|
||||
epii.set_stroke(BLACK, 50, background=True)
|
||||
|
||||
words = VGroup(
|
||||
TexText("in"),
|
||||
TexText(
|
||||
"in",
|
||||
"in",
|
||||
"3.14", " minutes"
|
||||
),
|
||||
)
|
||||
|
@ -1546,15 +1547,22 @@ class Thumbnail(Scene):
|
|||
words.shift(-words[0].get_center())
|
||||
words[0].set_opacity(0)
|
||||
|
||||
unit_size = 1.5
|
||||
unit_size = 2.0
|
||||
plane = ComplexPlane()
|
||||
plane.scale(unit_size)
|
||||
plane.add_coordinates()
|
||||
plane.shift(1.0 * DOWN)
|
||||
plane.add_coordinate_labels([*range(-3, 4), complex(0, -1), complex(0, 1)])
|
||||
|
||||
circle = Circle(
|
||||
radius=unit_size,
|
||||
color=YELLOW,
|
||||
)
|
||||
circle.set_stroke(GREY_B, 3)
|
||||
arc = Arc(0, PI, radius=unit_size)
|
||||
arc.set_stroke(BLUE, 10)
|
||||
circle = VGroup(arc.copy().set_stroke(BLACK, 20, background=True), circle, arc)
|
||||
|
||||
circle.move_to(plane.get_origin())
|
||||
# half_circle = VMobject()
|
||||
# half_circle.pointwise_become_partial(circle, 0, 0.5)
|
||||
# half_circle.set_stroke(RED, 6)
|
||||
|
@ -1562,19 +1570,22 @@ class Thumbnail(Scene):
|
|||
plane.n2p(0),
|
||||
plane.n2p(1),
|
||||
buff=0,
|
||||
color=POSITION_COLOR,
|
||||
fill_color=GREY_A,
|
||||
thickness=0.1
|
||||
)
|
||||
v_vect = Arrow(
|
||||
plane.n2p(1),
|
||||
plane.n2p(complex(1, 1)),
|
||||
buff=0,
|
||||
color=VELOCITY_COLOR,
|
||||
fill_color=YELLOW,
|
||||
thickness=0.1
|
||||
)
|
||||
vects = VGroup(p_vect, v_vect)
|
||||
vects.set_stroke(width=10)
|
||||
|
||||
self.add(plane)
|
||||
self.add(circle)
|
||||
self.add(vects)
|
||||
self.add(epii)
|
||||
self.add(words)
|
||||
# self.add(words)
|
||||
|
||||
self.embed()
|
||||
|
|
|
@ -339,6 +339,78 @@ class Thumbnail(Scene):
|
|||
self.add(group)
|
||||
|
||||
|
||||
class AltThumbnail(Scene):
|
||||
def construct(self):
|
||||
background = self.get_background()
|
||||
self.add(background)
|
||||
|
||||
bits = get_bit_grid(4, 4)
|
||||
bits.arrange_in_grid(h_buff=0.7, v_buff=0.5)
|
||||
boxes = get_bit_grid_boxes(bits)
|
||||
boxes.set_fill(BLACK, 1)
|
||||
|
||||
boxes[0].set_fill(TEAL_E)
|
||||
parity_boxes = VGroup(*(boxes[2**n] for n in range(4)))
|
||||
parity_boxes.set_fill(BLUE_E, 1)
|
||||
group = VGroup(boxes, bits)
|
||||
group.to_edge(DOWN, buff=LARGE_BUFF)
|
||||
|
||||
grouped_blocks = VGroup(*(boxes.copy() for x in range(4)))
|
||||
grouped_blocks.arrange_in_grid(buff_ratio=0.4)
|
||||
grouped_blocks.match_height(boxes)
|
||||
grouped_blocks.match_y(boxes)
|
||||
for n, gb in enumerate(grouped_blocks):
|
||||
gb.set_fill(BLACK)
|
||||
for k, box in enumerate(gb):
|
||||
if (k & (2**n)):
|
||||
box.set_fill(BLUE_E)
|
||||
grouped_blocks.to_edge(RIGHT, LARGE_BUFF)
|
||||
|
||||
VGroup(group, grouped_blocks).arrange(RIGHT, buff=1.5).to_edge(DOWN, LARGE_BUFF)
|
||||
|
||||
self.add(group)
|
||||
self.add(grouped_blocks)
|
||||
|
||||
title = Text("Hamming codes", font_size=72)
|
||||
title.to_edge(UP)
|
||||
shadow = VGroup()
|
||||
for w in np.linspace(50, 0, 50):
|
||||
tc = title.copy()
|
||||
tc.set_stroke(BLACK, width=w, opacity=0.02)
|
||||
tc.set_fill(opacity=0)
|
||||
shadow.add(tc)
|
||||
|
||||
self.add(shadow)
|
||||
self.add(title)
|
||||
return
|
||||
|
||||
|
||||
#
|
||||
words = TexText("Parity bits", font_size=72)
|
||||
words.next_to(boxes, LEFT, LARGE_BUFF)
|
||||
words.to_edge(UP)
|
||||
|
||||
words.move_to(boxes.get_corner(UL), DR)
|
||||
words.shift(0.5 * UL)
|
||||
|
||||
lines = VGroup()
|
||||
for n, v in zip(range(4), [UP, UP, LEFT, LEFT]):
|
||||
lines.add(Line(words.get_corner(DR), boxes[2**n].get_corner(v), buff=0.0))
|
||||
|
||||
lines.set_stroke(BLUE_B)
|
||||
|
||||
self.add(words)
|
||||
self.add(lines)
|
||||
|
||||
def get_background(self, n=25, k=100):
|
||||
choices = (Integer(0), Integer(1))
|
||||
background = VGroup(*(random.choice(choices).copy() for x in range(n * k)))
|
||||
background.arrange_in_grid(n, k)
|
||||
background.set_height(FRAME_HEIGHT)
|
||||
background.set_opacity(0.2)
|
||||
return background
|
||||
|
||||
|
||||
class DiskOfBits(Scene):
|
||||
def construct(self):
|
||||
# Setup disc
|
||||
|
@ -4764,24 +4836,25 @@ class EndScreen(Scene):
|
|||
|
||||
# Part 2
|
||||
|
||||
class Thumbnail2(Scene):
|
||||
class Thumbnail2(AltThumbnail):
|
||||
def construct(self):
|
||||
self.add(self.get_background())
|
||||
|
||||
code = ImageMobject("HammingCodeOneLine")
|
||||
code.set_width(FRAME_WIDTH - 3)
|
||||
br = SurroundingRectangle(code, buff=MED_SMALL_BUFF)
|
||||
br.set_fill(BLACK, 1)
|
||||
br.set_stroke(GREY_B, 2)
|
||||
code = Group(br, code)
|
||||
code.set_width(FRAME_WIDTH - 2)
|
||||
code.to_edge(DOWN, buff=LARGE_BUFF)
|
||||
self.add(code)
|
||||
|
||||
words = VGroup(
|
||||
# TexText("Why one line\\\\"),
|
||||
# TexText("finds bit errors"),
|
||||
TexText("Hamming codes\\\\"),
|
||||
TexText("in one(ish) line"),
|
||||
)
|
||||
words.set_width(FRAME_WIDTH - 3)
|
||||
words[0].to_edge(UP, buff=0.5)
|
||||
words[1].to_edge(DOWN, buff=0.5)
|
||||
|
||||
words[0].set_color(BLUE_C)
|
||||
words[1].set_color(BLUE_B)
|
||||
words = TexText("Hamming codes, part 2", "\\\\the elegance")
|
||||
words[1].set_color(BLUE)
|
||||
words.set_height(2.0)
|
||||
words.to_edge(UP)
|
||||
words.set_stroke(BLACK, 20, background=True)
|
||||
|
||||
self.add(words)
|
||||
|
||||
|
|
|
@ -184,6 +184,59 @@ class Thumbnail(Scene):
|
|||
self.embed()
|
||||
|
||||
|
||||
class AltThumbnail(Scene):
|
||||
def construct(self):
|
||||
dots = Dot().get_grid(9 * 5, 16 * 5, buff=MED_LARGE_BUFF)
|
||||
dots.set_height(FRAME_HEIGHT)
|
||||
dots.set_color(GREY_D)
|
||||
VGroup(*random.sample(list(dots), 50)).set_fill(YELLOW, 1)
|
||||
# self.add(dots)
|
||||
|
||||
title = Text("A better Bayes rule?")
|
||||
title.set_width(FRAME_WIDTH - 2)
|
||||
title.to_edge(UP, buff=1)
|
||||
title.set_stroke(BLACK, 25, background=True)
|
||||
self.add(title)
|
||||
|
||||
formula = Tex(
|
||||
"O(H | E)", "=", "O(H)", "{P(E | H) \\over P(E | \\neg H)",
|
||||
tex_to_color_map={"H": YELLOW, "E": BLUE}
|
||||
)
|
||||
formula.set_width(FRAME_WIDTH - 4)
|
||||
formula.set_y(-1)
|
||||
|
||||
H = formula.get_part_by_tex("H")
|
||||
E = formula.get_part_by_tex("E")
|
||||
hyp_label = Text("Hypothesis", color=YELLOW, font_size=24)
|
||||
hyp_label.next_to(H, UP, buff=1).shift_onto_screen()
|
||||
ev_label = Text("Evidence", color=BLUE, font_size=24)
|
||||
ev_label.next_to(E, DOWN, buff=1)
|
||||
|
||||
self.add(hyp_label, ev_label)
|
||||
self.add(Arrow(hyp_label, H, buff=0.1, color=YELLOW))
|
||||
self.add(Arrow(ev_label, E, buff=0.1, color=BLUE))
|
||||
|
||||
p_rect = SurroundingRectangle(formula[6:9])
|
||||
p_rect.set_stroke(GREY_B, 2)
|
||||
p_label = Text("Prior")
|
||||
p_label.next_to(p_rect, UP)
|
||||
# self.add(p_rect, p_label)
|
||||
|
||||
rect = SurroundingRectangle(formula[9:])
|
||||
rect.set_stroke(GREEN, 3)
|
||||
rect.set_fill(BLACK, 1)
|
||||
rect_label = Text("Bayes factor", color=GREEN)
|
||||
rect_label.match_width(rect)
|
||||
rect_label.next_to(rect, DOWN)
|
||||
|
||||
self.add(BackgroundRectangle(formula[:9]))
|
||||
self.add(rect)
|
||||
self.add(rect_label)
|
||||
self.add(formula)
|
||||
|
||||
# VGroup(formula, rect, rect_label).to_edge(DOWN)
|
||||
|
||||
|
||||
class MathAsDesign(Scene):
|
||||
def construct(self):
|
||||
# Setup
|
||||
|
|
|
@ -209,6 +209,58 @@ class Thumbnail(Scene):
|
|||
self.add(words)
|
||||
|
||||
|
||||
class AltThumbnail(ThreeDScene):
|
||||
def construct(self):
|
||||
lines = VGroup(*(Line(DOWN, UP) for x in range(2)))
|
||||
lines.set_height(FRAME_HEIGHT)
|
||||
lines.arrange(RIGHT, buff=FRAME_WIDTH / 3)
|
||||
lines.set_stroke(GREY_B, 3)
|
||||
self.add(lines)
|
||||
|
||||
mob_width = FRAME_WIDTH / 3 - 1
|
||||
|
||||
titles = VGroup(Text("Symmetry"), Text("Abstraction"), Text("Monsters"))
|
||||
titles.set_width(mob_width + 0.5)
|
||||
for title, x in zip(titles, [-1, 0, 1]):
|
||||
title.set_x(x * FRAME_WIDTH / 3)
|
||||
title.to_edge(UP)
|
||||
self.add(titles)
|
||||
|
||||
cube = Cube()
|
||||
cubes = Group(cube)
|
||||
for axis in [[1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1]]:
|
||||
for angle in [60 * DEGREES]:
|
||||
cubes.add(cube.copy().rotate(angle, axis))
|
||||
|
||||
cubes.rotate(95 * DEGREES, RIGHT)
|
||||
cubes.rotate(30 * DEGREES, UP)
|
||||
cubes.set_width(mob_width)
|
||||
cubes.match_x(titles[0])
|
||||
cubes.set_y(-0.5)
|
||||
cubes.set_color(BLUE_D)
|
||||
cubes.set_shadow(0.65)
|
||||
cubes.set_gloss(0.5)
|
||||
|
||||
self.add(cubes)
|
||||
|
||||
eq = Tex("f(gh)", "=", "(fg)h")
|
||||
eq[1].rotate(90 * DEGREES)
|
||||
eq.arrange(DOWN)
|
||||
|
||||
eq.match_height(cubes)
|
||||
eq.center()
|
||||
eq.match_y(cubes)
|
||||
self.add(eq)
|
||||
|
||||
monster = get_monster()
|
||||
monster.set_fill(GREY_BROWN)
|
||||
monster.set_gloss(0.5)
|
||||
monster.set_width(mob_width)
|
||||
monster.match_x(titles[2])
|
||||
monster.match_y(cubes)
|
||||
self.add(monster)
|
||||
|
||||
|
||||
class AskAboutFavoriteMegaNumber(TeacherStudentsScene):
|
||||
CONFIG = {
|
||||
"background_color": BLACK,
|
||||
|
|
|
@ -1448,7 +1448,7 @@ class DefinitionFirstVsLast(Scene):
|
|||
)
|
||||
self.wait()
|
||||
|
||||
# Highligh specific example
|
||||
# Highlight specific example
|
||||
full_rect = FullScreenRectangle()
|
||||
full_rect.set_fill(BLACK, opacity=0.75)
|
||||
sp, gp, hc = low_prog[:3].copy()
|
||||
|
@ -6189,7 +6189,7 @@ class FrameForFlow(Scene):
|
|||
self.add(screen_rect)
|
||||
|
||||
|
||||
class Thumbnail(DampedRotationPhaseFlow):
|
||||
class ThumbnailBackdrop(DampedRotationPhaseFlow):
|
||||
CONFIG = {
|
||||
"run_time": 10,
|
||||
}
|
||||
|
@ -6203,14 +6203,31 @@ class Thumbnail(DampedRotationPhaseFlow):
|
|||
if isinstance(mob, NumberPlane):
|
||||
self.remove(mob.coordinate_labels)
|
||||
|
||||
rect = FullScreenFadeRectangle()
|
||||
rect.set_opacity(0.5)
|
||||
self.add(rect)
|
||||
|
||||
class Thumbnail(Scene):
|
||||
def construct(self):
|
||||
im = ImageMobject("ExpMatThumbnailBackdrop")
|
||||
im.set_height(FRAME_HEIGHT)
|
||||
im.set_opacity(0.7)
|
||||
self.add(im)
|
||||
|
||||
# rect = FullScreenFadeRectangle()
|
||||
# rect.set_fill(opacity=0.3)
|
||||
# self.add(rect)
|
||||
|
||||
exp = get_matrix_exponential([[-1, -1], [1, 0]], scalar_tex="")
|
||||
exp.set_height(5)
|
||||
exp.set_stroke(BLACK, 30, background=True)
|
||||
self.add(exp)
|
||||
exp.set_stroke(BLACK, 50, opacity=0.5, background=True)
|
||||
|
||||
fuzz = VGroup()
|
||||
N = 100
|
||||
for w in np.linspace(150, 0, N):
|
||||
ec = exp.copy()
|
||||
ec.set_stroke(BLUE_E, width=w, opacity=(1 / N))
|
||||
ec.set_fill(opacity=0)
|
||||
fuzz.add(ec)
|
||||
|
||||
self.add(fuzz, exp)
|
||||
|
||||
self.embed()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue