Merge pull request #500 from 3b1b/ode

Ode
This commit is contained in:
Grant Sanderson 2019-04-22 10:17:47 -07:00 committed by GitHub
commit 83b1d3c5ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 5218 additions and 170 deletions

View file

@ -5,7 +5,7 @@ from active_projects.ode.part1.phase_space import *
from active_projects.ode.part1.wordy_scenes import *
OUTPUT_DIRECTORY = "ode/part1"
ALL_SCENE_CLASSES = [
SCENES_IN_ORDER = [
WhenChangeIsEasier,
VectorFieldTest,
IntroducePendulum,

View file

@ -1,19 +1,41 @@
from active_projects.ode.part2.staging import *
from active_projects.ode.part2.fourier_series import *
from active_projects.ode.part2.heat_equation import *
from active_projects.ode.part2.pi_scenes import *
from active_projects.ode.part2.wordy_scenes import *
OUTPUT_DIRECTORY = "ode/part2"
ALL_SCENE_CLASSES = [
# Tests
FourierOfPiSymbol,
FourierOfPiSymbol5,
FourierOfTrebleClef,
# CirclesDrawingWave,
# Scenes for video
ExplainCircleAnimations,
SCENES_IN_ORDER = [
PartTwoOfTour,
HeatEquationIntroTitle,
BrownianMotion,
BlackScholes,
ContrastChapters1And2,
FourierSeriesIntro,
FourierSeriesIntroBackground4,
FourierSeriesIntroBackground8,
FourierSeriesIntroBackground12,
FourierSeriesIntroBackground20,
ExplainCircleAnimations,
# FourierSeriesIntroBackground4,
# FourierSeriesIntroBackground8,
# FourierSeriesIntroBackground12,
TwoDBodyWithManyTemperatures,
TwoDBodyWithManyTemperaturesGraph,
TwoDBodyWithManyTemperaturesContour,
BringTwoRodsTogether,
ShowEvolvingTempGraphWithArrows,
# TodaysTargetWrapper,
WriteHeatEquation,
ReactionsToInitialHeatEquation,
TalkThrough1DHeatGraph,
ShowCubeFormation,
CompareInputsOfGeneralCaseTo1D,
ContrastXChangesToTChanges,
ShowPartialDerivativeSymbols,
WriteHeatEquation,
ShowCurvatureToRateOfChangeIntuition,
ContrastPDEToODE,
TransitionToTempVsTime,
Show1DAnd3DEquations,
#
AskAboutWhereEquationComesFrom,
DiscreteSetup,
]

View file

@ -102,11 +102,13 @@ class TourOfDifferentialEquations(MovingCameraScene):
"fill_color": BLACK,
},
"camera_config": {"background_color": DARKER_GREY},
"zoomed_thumbnail_index": 0,
}
def construct(self):
self.add_title()
self.show_thumbnails()
self.zoom_in_to_one_thumbnail()
# self.show_words()
def add_title(self):
@ -140,6 +142,7 @@ class TourOfDifferentialEquations(MovingCameraScene):
dots = TexMobject("\\dots")
dots.next_to(thumbnails[-1], RIGHT)
self.add_phase_space_preview(thumbnails[0])
self.add_heat_preview(thumbnails[1])
self.add_fourier_series(thumbnails[2])
self.add_matrix_exponent(thumbnails[3])
@ -164,9 +167,13 @@ class TourOfDifferentialEquations(MovingCameraScene):
)
self.play(Write(dots))
self.wait()
self.thumbnails = thumbnails
def zoom_in_to_one_thumbnail(self):
self.play(
self.camera_frame.replace,
thumbnails[0],
self.thumbnails[self.zoomed_thumbnail_index],
run_time=3,
)
self.wait()
@ -203,6 +210,11 @@ class TourOfDifferentialEquations(MovingCameraScene):
self.wait()
#
def add_phase_space_preview(self, thumbnail):
image = ImageMobject("LovePhaseSpace")
image.replace(thumbnail)
thumbnail.add(image)
def add_heat_preview(self, thumbnail):
image = ImageMobject("HeatSurfaceExample")
image.replace(thumbnail)

View file

@ -185,7 +185,7 @@ class ReasonForSolution(Scene):
cu_group.arrange(DOWN, buff=2)
group = VGroup(eq_word, s_word, cu_group)
group.arrange(RIGHT, buff=2)
words = VGroup(eq_word, s_word, u_word, c_word)
# words = VGroup(eq_word, s_word, u_word, c_word)
# Arrows
arrows = VGroup(

View file

@ -15,12 +15,28 @@ class FourierCirclesScene(Scene):
"circle_style": {
"stroke_width": 2,
},
"arrow_config": {
"buff": 0,
"max_tip_length_to_length_ratio": 0.35,
"tip_length": 0.15,
"max_stroke_width_to_length_ratio": 10,
"stroke_width": 2,
},
"use_vectors": True,
"base_frequency": 1,
"slow_factor": 0.25,
"center_point": ORIGIN,
"parametric_function_step_size": 0.001,
}
def setup(self):
self.slow_factor_tracker = ValueTracker(
self.slow_factor
)
def get_slow_factor(self):
return self.slow_factor_tracker.get_value()
#
def get_freqs(self):
n = self.n_circles
@ -68,12 +84,21 @@ class FourierCirclesScene(Scene):
color=color,
**self.circle_style,
)
circle.radial_line = Line(
line_points = (
circle.get_center(),
circle.get_start(),
color=WHITE,
**self.circle_style,
)
if self.use_vectors:
circle.radial_line = Arrow(
*line_points,
**self.arrow_config,
)
else:
circle.radial_line = Line(
*line_points,
color=WHITE,
**self.circle_style,
)
circle.add(circle.radial_line)
circle.freq = freq
circle.phase = phase
@ -85,7 +110,7 @@ class FourierCirclesScene(Scene):
def update_circle(self, circle, dt):
circle.rotate(
self.slow_factor * circle.freq * dt * TAU
self.get_slow_factor() * circle.freq * dt * TAU
)
circle.move_to(circle.center_func())
return circle
@ -98,9 +123,11 @@ class FourierCirclesScene(Scene):
def get_rotating_vector(self, circle):
vector = Vector(RIGHT, color=WHITE)
vector.add_updater(lambda v: v.put_start_and_end_on(
*circle.radial_line.get_start_and_end()
vector.add_updater(lambda v, dt: v.put_start_and_end_on(
circle.get_center(),
circle.get_start(),
))
circle.vector = vector
return vector
def get_circle_end_path(self, circles, color=YELLOW):
@ -123,24 +150,25 @@ class FourierCirclesScene(Scene):
return path
# TODO, this should be a general animated mobect
def get_drawn_path(self, circles, **kwargs):
def get_drawn_path(self, circles, stroke_width=2, **kwargs):
path = self.get_circle_end_path(circles, **kwargs)
broken_path = CurvesAsSubmobjects(path)
broken_path.curr_time = 0
def update_path(path, dt):
alpha = path.curr_time * self.slow_factor
alpha = path.curr_time * self.get_slow_factor()
n_curves = len(path)
for a, sp in zip(np.linspace(0, 1, n_curves), path):
b = alpha - a
if b < 0:
width = 0
else:
width = 2 * (1 - (b % 1))
sp.set_stroke(YELLOW, width=width)
width = stroke_width * (1 - (b % 1))
sp.set_stroke(width=width)
path.curr_time += dt
return path
broken_path.set_color(YELLOW)
broken_path.add_updater(update_path)
return broken_path
@ -168,7 +196,7 @@ class FourierCirclesScene(Scene):
top_point = wave_copies.get_top()
wave.creation = ShowCreation(
wave,
run_time=(1 / self.slow_factor),
run_time=(1 / self.get_slow_factor()),
rate_func=linear,
)
cycle_animation(wave.creation)
@ -178,7 +206,7 @@ class FourierCirclesScene(Scene):
def update_wave_copies(wcs):
index = int(
wave.creation.total_time * self.slow_factor
wave.creation.total_time * self.get_slow_factor()
)
wcs[:index].match_style(wave)
wcs[index:].set_stroke(width=0)
@ -322,36 +350,193 @@ class FourierOfTrebleClef(FourierOfPiSymbol):
"n_circles": 100,
"run_time": 10,
"start_drawn": True,
"file_name": "TrebleClef",
"height": 7.5,
}
def get_shape(self):
shape = SVGMobject(self.file_name)
return shape
def get_path(self):
path = SVGMobject("TrebleClef")
path = path.family_members_with_points()[0]
path.set_height(7.5)
shape = self.get_shape()
path = shape.family_members_with_points()[0]
path.set_height(self.height)
path.set_fill(opacity=0)
path.set_stroke(WHITE, 0)
return path
class FourierOfIP(FourierOfTrebleClef):
CONFIG = {
"file_name": "IP_logo2",
"height": 6,
"n_circles": 100,
}
# def construct(self):
# path = self.get_path()
# self.add(path)
def get_shape(self):
shape = SVGMobject(self.file_name)
return shape
def get_path(self):
shape = self.get_shape()
path = shape.family_members_with_points()[0]
path.add_line_to(path.get_start())
# path.make_smooth()
path.set_height(self.height)
path.set_fill(opacity=0)
path.set_stroke(WHITE, 0)
return path
class FourierOfEighthNote(FourierOfTrebleClef):
CONFIG = {
"file_name": "EighthNote"
}
class FourierOfN(FourierOfTrebleClef):
CONFIG = {
"height": 6,
"n_circles": 1000,
}
def get_shape(self):
return TexMobject("N")
class FourierNailAndGear(FourierOfTrebleClef):
CONFIG = {
"height": 6,
"n_circles": 200,
"run_time": 100,
"slow_factor": 0.01,
"parametric_function_step_size": 0.0001,
"arrow_config": {
"tip_length": 0.1,
"stroke_width": 2,
}
}
def get_shape(self):
shape = SVGMobject("Nail_And_Gear")[1]
return shape
class FourierBatman(FourierOfTrebleClef):
CONFIG = {
"height": 4,
"n_circles": 100,
"run_time": 10,
"arrow_config": {
"tip_length": 0.1,
"stroke_width": 2,
}
}
def get_shape(self):
shape = SVGMobject("BatmanLogo")[1]
return shape
class FourierHeart(FourierOfTrebleClef):
CONFIG = {
"height": 4,
"n_circles": 100,
"run_time": 10,
"arrow_config": {
"tip_length": 0.1,
"stroke_width": 2,
}
}
def get_shape(self):
shape = SuitSymbol("hearts")
return shape
def get_drawn_path(self, *args, **kwargs):
kwargs["stroke_width"] = 5
path = super().get_drawn_path(*args, **kwargs)
path.set_color(PINK)
return path
class FourierNDQ(FourierOfTrebleClef):
CONFIG = {
"height": 4,
"n_circles": 1000,
"run_time": 10,
"arrow_config": {
"tip_length": 0.1,
"stroke_width": 2,
}
}
def get_shape(self):
path = VMobject()
shape = TexMobject("Hayley")
for sp in shape.family_members_with_points():
path.append_points(sp.points)
return path
class FourierGoogleG(FourierOfTrebleClef):
CONFIG = {
"n_circles": 10,
"height": 5,
"g_colors": [
"#4285F4",
"#DB4437",
"#F4B400",
"#0F9D58",
]
}
def get_shape(self):
g = SVGMobject("google_logo")[5]
g.center()
self.add(g)
return g
def get_drawn_path(self, *args, **kwargs):
kwargs["stroke_width"] = 7
path = super().get_drawn_path(*args, **kwargs)
blue, red, yellow, green = self.g_colors
path[:250].set_color(blue)
path[250:333].set_color(green)
path[333:370].set_color(yellow)
path[370:755].set_color(red)
path[755:780].set_color(yellow)
path[780:860].set_color(green)
path[860:].set_color(blue)
return path
class ExplainCircleAnimations(FourierCirclesScene):
CONFIG = {
# "n_circles": 100,
"n_circles": 20,
"n_circles": 100,
"center_point": 2 * DOWN,
"n_top_circles": 9,
# "slow_factor": 0.1,
"path_height": 3,
}
def construct(self):
self.add_path()
self.add_circles()
self.wait(8)
self.organize_circles_in_a_row()
self.show_frequencies()
self.show_examples_for_frequencies()
self.show_as_vectors()
self.show_vector_sum()
self.moons_of_moons_of_moons()
self.tweak_starting_vectors()
def add_path(self):
@ -366,11 +551,9 @@ class ExplainCircleAnimations(FourierCirclesScene):
self.drawn_path = self.get_drawn_path(self.circles)
self.add(self.drawn_path)
self.wait(8)
def organize_circles_in_a_row(self):
circles = self.circles
top_circles = circles[:self.n_top_circles].deepcopy()
top_circles = circles[:self.n_top_circles].copy()
center_trackers = VGroup()
for circle in top_circles:
@ -435,6 +618,9 @@ class ExplainCircleAnimations(FourierCirclesScene):
)
self.wait(2)
self.freq_numbers = freq_numbers
self.freq_word = freq_word
def show_examples_for_frequencies(self):
top_circles = self.top_circles
c1, c2, c3 = [
@ -478,41 +664,163 @@ class ExplainCircleAnimations(FourierCirclesScene):
])
)
self.wait(3)
self.play(FadeOut(self.freq_word))
def show_as_vectors(self):
top_circles = self.top_circles
top_vectors = self.get_rotating_vectors(top_circles)
top_vectors.set_color(WHITE)
original_circles = top_circles.copy()
self.play(
top_circles.set_stroke, {"width": 0.5},
FadeIn(top_vectors),
top_circles.set_opacity, 0,
)
self.wait(3)
self.play(
top_circles.match_style, original_circles
)
self.remove(top_vectors)
self.top_vectors = top_vectors
def show_vector_sum(self):
top_circles = self.top_circles
top_vectors = self.top_vectors
trackers = self.center_trackers.copy()
trackers.sort(
submob_func=lambda t: abs(t.circle.freq - 0.1)
)
plane = self.plane = NumberPlane(
x_min=-3,
x_max=3,
y_min=-2,
y_max=2,
axis_config={
"stroke_color": LIGHT_GREY,
}
)
plane.set_stroke(width=1)
plane.fade(0.5)
plane.move_to(self.center_point)
self.play(
FadeOut(self.path),
FadeOut(self.drawn_path),
FadeOut(self.circles),
self.slow_factor_tracker.set_value, 0.05,
)
self.add(plane, self.path)
self.play(FadeIn(plane))
def moons_of_moons_of_moons(self):
pass
new_circles = VGroup()
last_tracker = None
for tracker in trackers:
if last_tracker:
tracker.new_location_func = last_tracker.circle.get_start
else:
tracker.new_location_func = lambda: self.center_point
original_circle = tracker.circle
tracker.circle = original_circle.copy()
tracker.circle.center_func = tracker.get_location
new_circles.add(tracker.circle)
self.add(tracker, tracker.circle)
start_point = tracker.get_location()
self.play(
UpdateFromAlphaFunc(
tracker, lambda t, a: t.move_to(
interpolate(
start_point,
tracker.new_location_func(),
a,
)
),
run_time=2
)
)
tracker.add_updater(lambda t: t.move_to(
t.new_location_func()
))
self.wait(2)
last_tracker = tracker
self.wait(3)
self.clear()
self.slow_factor_tracker.set_value(0.1)
self.add(
self.top_circles,
self.freq_numbers,
self.path,
)
self.add_circles()
for tc in self.top_circles:
for c in self.circles:
if c.freq == tc.freq:
tc.rotate(
angle_of_vector(c.get_start() - c.get_center()) -
angle_of_vector(tc.get_start() - tc.get_center())
)
self.wait(10)
def tweak_starting_vectors(self):
pass
top_circles = self.top_circles
circles = self.circles
path = self.path
drawn_path = self.drawn_path
new_path = self.get_new_path()
new_coefs = self.get_coefficients_of_path(new_path)
new_circles = self.get_circles(coefficients=new_coefs)
new_top_circles = VGroup()
new_top_vectors = VGroup()
for top_circle in top_circles:
for circle in new_circles:
if circle.freq == top_circle.freq:
new_top_circle = circle.copy()
new_top_circle.center_func = top_circle.get_center
new_top_vector = self.get_rotating_vector(
new_top_circle
)
new_top_circles.add(new_top_circle)
new_top_vectors.add(new_top_vector)
self.play(
self.slow_factor_tracker.set_value, 0,
FadeOut(drawn_path)
)
self.wait()
self.play(
ReplacementTransform(top_circles, new_top_circles),
ReplacementTransform(circles, new_circles),
FadeOut(path),
run_time=3,
)
new_drawn_path = self.get_drawn_path(
new_circles, stroke_width=4,
)
self.add(new_drawn_path)
self.slow_factor_tracker.set_value(0.1)
self.wait(20)
#
def get_path(self):
tex = TexMobject("f")
path = tex.family_members_with_points()[0]
def configure_path(self, path):
path.set_stroke(WHITE, 1)
path.set_fill(opacity=0)
path.set_fill(BLACK, opacity=1)
path.set_height(self.path_height)
path.move_to(self.center_point)
return path
def get_path(self):
tex = TexMobject("f")
path = tex.family_members_with_points()[0]
self.configure_path(path)
return path
# return Square().set_height(3)
def get_new_path(self):
shape = SVGMobject("TrebleClef")
path = shape.family_members_with_points()[0]
self.configure_path(path)
path.scale(1.5, about_edge=DOWN)
return path

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,142 @@
from big_ol_pile_of_manim_imports import *
from active_projects.ode.part2.wordy_scenes import WriteHeatEquationTemplate
class ReactionsToInitialHeatEquation(PiCreatureScene):
def construct(self):
randy = self.pi_creature
randy.set_color(BLUE_C)
randy.center()
point = VectorizedPoint().next_to(randy, UL, LARGE_BUFF)
randy.add_updater(lambda r: r.look_at(point))
self.play(randy.change, "horrified")
self.wait()
self.play(randy.change, "pondering")
self.wait()
self.play(
randy.change, "confused",
point.next_to, randy, UR, LARGE_BUFF,
)
self.wait(2)
self.play(
point.shift, 2 * DOWN,
randy.change, "horrified"
)
self.wait(4)
class ContrastPDEToODE(TeacherStudentsScene):
CONFIG = {
"random_seed": 2,
}
def construct(self):
student = self.students[2]
pde, ode = words = VGroup(*[
TextMobject(
text + "\\\\",
"Differential\\\\",
"Equation"
)
for text in ("Partial", "Ordinary")
])
pde[0].set_color(YELLOW)
ode[0].set_color(BLUE)
for word in words:
word.arrange(DOWN, aligned_edge=LEFT)
words.arrange(RIGHT, buff=LARGE_BUFF)
words.next_to(student.get_corner(UR), UP, MED_LARGE_BUFF)
words.shift(UR)
lt = TexMobject("<")
lt.scale(1.5)
lt.move_to(Line(pde.get_right(), ode.get_left()))
for pi in self.pi_creatures:
pi.add_updater(lambda p: p.look_at(pde))
self.play(
FadeInFromDown(VGroup(words, lt)),
student.change, "raise_right_hand",
)
self.play(
self.get_student_changes("pondering", "pondering", "hooray"),
self.teacher.change, "happy"
)
self.wait(3)
self.play(
Swap(ode, pde),
self.teacher.change, "raise_right_hand",
self.get_student_changes(
"erm", "sassy", "confused"
)
)
self.look_at(words)
self.change_student_modes(
"thinking", "thinking", "tease",
)
self.wait(3)
class AskAboutWhereEquationComesFrom(TeacherStudentsScene, WriteHeatEquationTemplate):
def construct(self):
equation = self.get_d1_equation()
equation.move_to(self.hold_up_spot, DOWN)
self.play(
FadeInFromDown(equation),
self.teacher.change, "raise_right_hand"
)
self.student_says(
"Um...why?",
target_mode="sassy",
student_index=2,
bubble_kwargs={"direction": RIGHT},
)
self.change_student_modes(
"confused", "confused", "sassy",
)
self.wait()
self.play(
self.teacher.change, "pondering",
)
self.wait(2)
class AskWhyRewriteIt(TeacherStudentsScene):
def construct(self):
self.student_says(
"Why?", student_index=1,
bubble_kwargs={"height": 2, "width": 2},
)
self.students[1].bubble = None
self.teacher_says(
"One step closer\\\\to derivatives"
)
self.change_student_modes(
"thinking", "thinking", "thinking",
look_at_arg=4 * LEFT + 2 * UP
)
self.wait(2)
class ReferenceKhanVideo(TeacherStudentsScene):
def construct(self):
khan_logo = ImageMobject("KhanLogo")
khan_logo.set_height(1)
khan_logo.next_to(self.teacher, UP, buff=2)
khan_logo.shift(2 * LEFT)
self.play(
self.teacher.change, "raise_right_hand",
)
self.change_student_modes(
"thinking", "pondering", "thinking",
look_at_arg=self.screen
)
self.wait()
self.play(FadeInFromDown(khan_logo))
self.look_at(self.screen)
self.wait(15)

View file

@ -0,0 +1,35 @@
from big_ol_pile_of_manim_imports import *
TIME_COLOR = YELLOW
X_COLOR = GREEN
def get_heat_equation():
pass
def temperature_to_color(temp, min_temp=-1, max_temp=1):
colors = [BLUE, TEAL, GREEN, YELLOW, "#ff0000"]
alpha = inverse_interpolate(min_temp, max_temp, temp)
index, sub_alpha = integer_interpolate(
0, len(colors) - 1, alpha
)
return interpolate_color(
colors[index], colors[index + 1], sub_alpha
)
def two_d_temp_func(x, y, t):
return np.sum([
c * np.sin(f * var) * np.exp(-(f**2) * t)
for c, f, var in [
(0.2, 1, x),
(0.3, 3, x),
(0.02, 5, x),
(0.01, 7, x),
(0.5, 2, y),
(0.1, 10, y),
(0.01, 20, y),
]
])

View file

@ -1,22 +1,794 @@
from big_ol_pile_of_manim_imports import *
from active_projects.ode.part1.staging import TourOfDifferentialEquations
class FourierSeriesIntro(Scene):
class PartTwoOfTour(TourOfDifferentialEquations):
CONFIG = {
"zoomed_thumbnail_index": 1,
}
def construct(self):
title = TextMobject(
"Fourier ", "Series", ":",
" An origin story",
arg_separator="",
self.add_title()
self.show_thumbnails()
self.zoom_in_to_one_thumbnail()
def zoom_in_to_one_thumbnail(self):
frame = self.camera_frame
thumbnails = self.thumbnails
ode = TextMobject("Ordinary\\\\", "Differential Equation")
pde = TextMobject("Partial\\\\", "Differential Equation")
for word, thumbnail, vect in zip([ode, pde], thumbnails, [DOWN, UP]):
word.match_width(thumbnail)
word.next_to(thumbnail, vect)
ode[0].set_color(BLUE)
pde[0].set_color(YELLOW)
self.add(ode)
frame.save_state()
self.play(
frame.replace,
thumbnails[0],
run_time=1,
)
title.scale(2)
title.to_edge(UP)
image = ImageMobject("Joseph Fourier")
image.set_height(5)
image.next_to(title, DOWN, MED_LARGE_BUFF)
image.to_edge(LEFT)
name = TextMobject("Joseph", "Fourier")
name.next_to(image, DOWN)
self.play(
Restore(frame, run_time=3),
)
self.play(
TransformFromCopy(ode, pde),
)
self.play(
ApplyMethod(
frame.replace, thumbnails[1],
path_arc=(-30 * DEGREES),
run_time=3
),
)
self.wait()
class BrownianMotion(Scene):
CONFIG = {
"wait_time": 60,
"L": 3, # Box in [-L, L] x [-L, L]
"n_particles": 100,
"m1": 1,
"m2": 100,
"r1": 0.05,
"r2": 0.5,
"max_v": 5,
"random_seed": 2,
}
def construct(self):
self.add_title()
self.add_particles()
self.wait(self.wait_time)
def add_title(self):
square = Square(side_length=2 * self.L)
title = TextMobject("Brownian motion")
title.scale(1.5)
title.next_to(square, UP)
self.add(square)
self.add(title)
def add_particles(self):
m1 = self.m1
m2 = self.m2
r1 = self.r1
r2 = self.r2
L = self.L
max_v = self.max_v
n_particles = self.n_particles
lil_particles = VGroup(*[
self.get_particle(m1, r1, L, max_v)
for k in range(n_particles)
])
big_particle = self.get_particle(m2, r2, L=r2, max_v=0)
big_particle.set_fill(YELLOW, 1)
for p in lil_particles:
if self.are_colliding(p, big_particle):
lil_particles.remove(p)
all_particles = VGroup(big_particle, *lil_particles)
all_particles.add_updater(self.update_particles)
path = self.get_traced_path(big_particle)
self.add(all_particles)
self.add(path)
self.particles = all_particles
self.big_particle = big_particle
self.path = path
def get_particle(self, m, r, L, max_v):
dot = Dot(radius=r)
dot.set_fill(WHITE, 0.7)
dot.mass = m
dot.radius = r
dot.center = op.add(
np.random.uniform(-L + r, L - r) * RIGHT,
np.random.uniform(-L + r, L - r) * UP
)
dot.move_to(dot.center)
dot.velocity = rotate_vector(
np.random.uniform(0, max_v) * RIGHT,
np.random.uniform(0, TAU),
)
return dot
def are_colliding(self, p1, p2):
d = get_norm(p1.get_center() - p2.get_center())
return (d < p1.radius + p2.radius)
def get_traced_path(self, particle):
path = VMobject()
path.set_stroke(BLUE, 3)
path.start_new_path(particle.get_center())
buff = 0.02
def update_path(path):
new_point = particle.get_center()
if get_norm(new_point - path.get_last_point()) > buff:
path.add_line_to(new_point)
path.add_updater(update_path)
return path
def update_particles(self, particles, dt):
for p1 in particles:
p1.center += p1.velocity * dt
# Check particle collisions
buff = 0.01
for p2 in particles:
if p1 is p2:
continue
v = p2.center - p1.center
dist = get_norm(v)
r_sum = p1.radius + p2.radius
diff = dist - r_sum
if diff < 0:
unit_v = v / dist
p1.center += (diff - buff) * unit_v / 2
p2.center += -(diff - buff) * unit_v / 2
u1 = p1.velocity
u2 = p2.velocity
m1 = p1.mass
m2 = p2.mass
v1 = (
(m2 * (u2 - u1) + m1 * u1 + m2 * u2) /
(m1 + m2)
)
v2 = (
(m1 * (u1 - u2) + m1 * u1 + m2 * u2) /
(m1 + m2)
)
p1.velocity = v1
p2.velocity = v2
# Check edge collisions
r1 = p1.radius
c1 = p1.center
for i in [0, 1]:
if abs(c1[i]) + r1 > self.L:
c1[i] = np.sign(c1[i]) * (self.L - r1)
p1.velocity[i] *= -1 * op.mul(
np.sign(p1.velocity[i]),
np.sign(c1[i])
)
for p in particles:
p.move_to(p.center)
return particles
class AltBrownianMotion(BrownianMotion):
CONFIG = {
"wait_time": 20,
"n_particles": 100,
"m2": 10,
}
class BlackScholes(AltBrownianMotion):
def construct(self):
# For some reason I'm amused by the thought
# Of this graph perfectly matching the Brownian
# Motion y-coordiante
self.add_title()
self.add_particles()
self.particles.set_opacity(0)
self.remove(self.path)
self.add_graph()
self.wait(self.wait_time)
def add_title(self):
title = TextMobject("Black-Sholes equations")
title.scale(1.5)
title.next_to(2 * UP, UP)
equation = TexMobject(
"{\\partial V \\over \\partial t}", "+",
"\\frac{1}{2} \\sigma^2 S^2",
"{\\partial^2 V \\over \\partial S^2}", "+",
"rS", "{\\partial V \\over \\partial S}",
"-rV", "=", "0",
)
equation.scale(0.8)
equation.next_to(title, DOWN)
self.add(title)
self.add(equation)
self.title = title
self.equation = equation
def add_graph(self):
axes = Axes(
x_min=-1,
x_max=20,
y_min=0,
y_max=10,
number_line_config={
"unit_size": 0.5,
},
)
axes.set_height(4)
axes.move_to(DOWN)
def get_graph_point():
return axes.c2p(
self.get_time(),
5 + 2 * self.big_particle.get_center()[1]
)
graph = VMobject()
graph.match_style(self.path)
graph.start_new_path(get_graph_point())
graph.add_updater(
lambda g: g.add_line_to(get_graph_point())
)
self.add(axes)
self.add(graph)
class ContrastChapters1And2(Scene):
def construct(self):
c1_frame, c2_frame = frames = VGroup(*[
ScreenRectangle(height=3.5)
for x in range(2)
])
frames.arrange(RIGHT, buff=LARGE_BUFF)
c1_title, c2_title = titles = VGroup(
TextMobject("Chapter 1"),
TextMobject("Chapter 2"),
)
titles.scale(1.5)
ode, pde = des = VGroup(
TextMobject(
"Ordinary",
"Differential Equations\\\\",
"ODEs",
),
TextMobject(
"Partial",
"Differential Equations\\\\",
"PDEs",
),
)
ode[0].set_color(BLUE)
pde[0].set_color(YELLOW)
for de in des:
de[-1][0].match_color(de[0])
de[-1].scale(1.5, about_point=de.get_top())
for title, frame, de in zip(titles, frames, des):
title.next_to(frame, UP)
de.match_width(frame)
de.next_to(frame, DOWN)
lt = TexMobject("<")
lt.move_to(Line(ode.get_right(), pde.get_left()))
lt.scale(2, about_edge=UP)
c1_words = TextMobject(
"They're", "really\\\\", "{}",
"freaking", "hard\\\\",
"to", "solve\\\\",
)
c1_words.set_height(0.5 * c1_frame.get_height())
c1_words.move_to(c1_frame)
c2_words = TextMobject(
"They're", "really", "\\emph{really}\\\\",
"freaking", "hard\\\\",
"to", "solve\\\\",
)
c2_words.set_color_by_tex("\\emph", YELLOW)
c2_words.move_to(c2_frame)
edit_shift = MED_LARGE_BUFF * RIGHT
c2_edits = VGroup(
TextMobject("sometimes").next_to(
c2_words[1:3], UP,
aligned_edge=LEFT,
),
Line(
c2_words[1].get_left(),
c2_words[2].get_right(),
stroke_width=8,
),
TextMobject("not too").next_to(
c2_words[3], LEFT,
),
Line(
c2_words[3].get_left(),
c2_words[3].get_right(),
stroke_width=8,
),
)
c2_edits.set_color(RED)
c2_edits[2:].shift(edit_shift)
self.add(titles)
self.add(frames)
self.add(des)
self.wait()
self.play(LaggedStartMap(
FadeInFromDown, c1_words,
lag_ratio=0.1,
))
self.wait()
# self.play(FadeIn(ode))
self.play(
# TransformFromCopy(ode, pde),
TransformFromCopy(c1_words, c2_words),
Write(lt)
)
self.wait()
self.play(
Write(c2_edits[:2], run_time=1),
)
self.play(
c2_words[3:5].shift, edit_shift,
Write(c2_edits[2:]),
run_time=1,
)
self.wait()
class ShowCubeFormation(ThreeDScene):
CONFIG = {
"camera_config": {
"shading_factor": 1.0,
},
"color": False,
}
def construct(self):
light_source = self.camera.light_source
light_source.move_to(np.array([-6, -3, 6]))
cube = Cube(
side_length=4,
fill_color=GREY,
stroke_color=WHITE,
stroke_width=0.5,
)
cube.set_fill(opacity=1)
if self.color:
# cube[0].set_color(BLUE)
# cube[1].set_color(RED)
# for face in cube[2:]:
# face.set_color([BLUE, RED])
cube.color_using_background_image("VerticalTempGradient")
# light_source.next_to(cube, np.array([1, -1, 1]), buff=2)
cube_3d = cube.copy()
cube_2d = cube_3d.copy().stretch(0, 2)
cube_1d = cube_2d.copy().stretch(0, 1)
cube_0d = cube_1d.copy().stretch(0, 0)
cube.become(cube_0d)
self.set_camera_orientation(
phi=70 * DEGREES,
theta=-145 * DEGREES,
)
self.begin_ambient_camera_rotation(rate=0.05)
for target in [cube_1d, cube_2d, cube_3d]:
self.play(
Transform(cube, target, run_time=1.5)
)
self.wait(8)
class ShowCubeFormationWithColor(ShowCubeFormation):
CONFIG = {
"color": True,
}
class ShowRect(Scene):
CONFIG = {
"height": 1,
"width": 3,
}
def construct(self):
rect = Rectangle(
height=self.height,
width=self.width,
)
rect.set_color(YELLOW)
self.play(ShowCreationThenFadeOut(rect))
class ShowSquare(ShowRect):
CONFIG = {
"height": 1,
"width": 1,
}
class ShowHLine(Scene):
def construct(self):
line = Line(LEFT, RIGHT)
line.set_color(BLUE)
self.play(ShowCreationThenFadeOut(line))
class ShowCross(Scene):
def construct(self):
cross = Cross(Square())
cross.set_width(3)
cross.set_height(1, stretch=True)
self.play(ShowCreation(cross))
class TwoBodyEquations(Scene):
def construct(self):
kw = {
"tex_to_color_map": {
"x_1": LIGHT_GREY,
"y_1": LIGHT_GREY,
"x_2": BLUE,
"y_2": BLUE,
"=": WHITE,
}
}
equations = VGroup(
TexMobject(
"{d^2 x_1 \\over dt^2}",
"=",
"{x_2 - x_1 \\over m_1 \\left(",
"(x_2 - x_1)^2 + (y_2 - y_1)^2",
"\\right)^{3/2}",
**kw
),
TexMobject(
"{d^2 y_1 \\over dt^2}",
"=",
"{y_2 - y_1 \\over m_1 \\left(",
"(x_2 - x_1)^2 + (y_2 - y_1)^2",
"\\right)^{3/2}",
**kw
),
TexMobject(
"{d^2 x_2 \\over dt^2}",
"=",
"{x_1 - x_2 \\over m_2 \\left(",
"(x_2 - x_1)^2 + (y_2 - y_1)^2",
"\\right)^{3/2}",
**kw
),
TexMobject(
"{d^2 y_2 \\over dt^2}",
"=",
"{y_1 - y_2 \\over m_2 \\left(",
"(x_2 - x_1)^2 + (y_2 - y_1)^2",
"\\right)^{3/2}",
**kw
),
)
equations.arrange(DOWN, buff=LARGE_BUFF)
equations.set_height(6)
equations.to_edge(LEFT)
variables = VGroup()
lhss = VGroup()
rhss = VGroup()
for equation in equations:
variable = equation[1]
lhs = equation[:4]
rhs = equation[4:]
variables.add(variable)
lhss.add(lhs)
rhss.add(rhs)
lhss_copy = lhss.copy()
for variable, lhs in zip(variables, lhss):
variable.save_state()
variable.match_height(lhs)
variable.scale(0.7)
variable.move_to(lhs, LEFT)
self.play(LaggedStart(*[
FadeInFrom(v, RIGHT)
for v in variables
]))
self.wait()
self.play(
LaggedStartMap(Restore, variables),
FadeIn(
lhss_copy,
remover=True,
lag_ratio=0.1,
run_time=2,
)
)
self.add(lhss)
self.wait()
self.play(LaggedStartMap(
FadeIn, rhss
))
self.wait()
self.play(
LaggedStart(*[
ShowCreationThenFadeAround(lhs[:3])
for lhs in lhss
])
)
self.wait()
self.play(
LaggedStartMap(
ShowCreationThenFadeAround,
rhss,
)
)
self.wait()
class LaplacianIntuition(SpecialThreeDScene):
CONFIG = {
"three_d_axes_config": {
"x_min": -5,
"x_max": 5,
"y_min": -5,
"y_max": 5,
},
"surface_resolution": 32,
}
def construct(self):
axes = self.get_axes()
axes.scale(0.5, about_point=ORIGIN)
self.set_camera_to_default_position()
self.begin_ambient_camera_rotation()
def func(x, y):
return np.array([
x, y,
2.7 + 0.5 * (np.sin(x) + np.cos(y)) -
0.025 * (x**2 + y**2)
])
surface_config = {
"u_min": -5,
"u_max": 5,
"v_min": -5,
"v_max": 5,
"resolution": self.surface_resolution,
}
# plane = ParametricSurface(
# lambda u, v: np.array([u, v, 0]),
# **surface_config
# )
# plane.set_stroke(WHITE, width=0.1)
# plane.set_fill(WHITE, opacity=0.1)
plane = Square(
side_length=10,
stroke_width=0,
fill_color=WHITE,
fill_opacity=0.1,
)
plane.center()
plane.set_shade_in_3d(True)
surface = ParametricSurface(
func, **surface_config
)
surface.set_stroke(BLUE, width=0.1)
surface.set_fill(BLUE, opacity=0.25)
self.add(axes, plane, surface)
point = VectorizedPoint(np.array([2, -2, 0]))
dot = Dot()
dot.set_color(GREEN)
dot.add_updater(lambda d: d.move_to(point))
line = always_redraw(lambda: DashedLine(
point.get_location(),
func(*point.get_location()[:2]),
background_image_file="VerticalTempGradient",
))
circle = Circle(radius=0.25)
circle.set_color(YELLOW)
circle.insert_n_curves(20)
circle.add_updater(lambda m: m.move_to(point))
circle.set_shade_in_3d(True)
surface_circle = always_redraw(
lambda: circle.copy().apply_function(
lambda p: func(*p[:2])
).shift(
0.02 * IN
).color_using_background_image("VerticalTempGradient")
)
self.play(FadeInFromLarge(dot))
self.play(ShowCreation(line))
self.play(TransformFromCopy(dot, circle))
self.play(
Transform(
circle.copy(),
surface_circle.copy().clear_updaters(),
remover=True,
)
)
self.add(surface_circle)
self.wait()
for vect in [4 * LEFT, DOWN, 4 * RIGHT, UP]:
self.play(
point.shift, vect,
run_time=3,
)
class StrogatzMention(PiCreatureScene):
def construct(self):
self.show_book()
self.show_motives()
self.show_pages()
def show_book(self):
morty = self.pi_creature
book = ImageMobject("InfinitePowers")
book.set_height(5)
book.to_edge(LEFT)
steve = ImageMobject("Strogatz_by_bricks")
steve.set_height(5)
steve.to_edge(LEFT)
name = TextMobject("Steven Strogatz")
name.match_width(steve)
name.next_to(steve, DOWN)
self.think(
"Hmm...many good\\\\lessons here...",
run_time=1
)
self.wait()
self.play(FadeInFromDown(steve))
self.wait()
self.play(
FadeInFrom(book, DOWN),
steve.shift, 4 * RIGHT,
RemovePiCreatureBubble(
morty, target_mode="thinking"
)
)
self.wait(3)
self.play(
FadeOut(steve),
FadeOut(morty),
)
self.book = book
def show_motives(self):
motives = VGroup(
TextMobject("1) Scratch and itch"),
TextMobject("2) Make people love math"),
)
motives.scale(1.5)
motives.arrange(
DOWN, LARGE_BUFF,
aligned_edge=LEFT,
)
motives.move_to(
Line(
self.book.get_right(),
FRAME_WIDTH * RIGHT / 2
)
)
motives.to_edge(UP)
for motive in motives:
self.play(FadeInFromDown(motive))
self.wait(2)
self.play(FadeOut(motives))
def show_pages(self):
book = self.book
pages = Group(*[
ImageMobject("IP_Sample_Page{}".format(i))
for i in range(1, 4)
])
for page in pages:
page.match_height(book)
page.next_to(book, RIGHT)
last_page = VectorizedPoint()
for page in pages:
self.play(
FadeOut(last_page),
FadeIn(page)
)
self.wait()
last_page = page
self.play(FadeOut(last_page))
def create_pi_creature(self):
return Mortimer().to_corner(DR)
class Thumbnail(Scene):
def construct(self):
image = ImageMobject("HeatSurfaceExampleFlipped")
image.set_height(6.5)
image.to_edge(DOWN, buff=-SMALL_BUFF)
self.add(image)
self.add(name)
equation = TexMobject(
"{\\partial {T} \\over \\partial {t}}", "=",
"\\alpha", "\\nabla^2 {T}",
tex_to_color_map={
"{t}": YELLOW,
"{T}": RED,
}
)
equation.scale(2)
equation.to_edge(UP)
self.add(equation)
Group(equation, image).shift(1.5 * RIGHT)
question = TextMobject("What is\\\\this?")
question.scale(2.5)
question.to_edge(LEFT)
arrow = Arrow(
question.get_top(),
equation.get_left(),
buff=0.5,
path_arc=-90 * DEGREES,
)
arrow.set_stroke(width=5)
self.add(question, arrow)
class ShowNewton(Scene):
def construct(self):
pass
class ShowCupOfWater(Scene):
def construct(self):
pass

View file

@ -0,0 +1,785 @@
from big_ol_pile_of_manim_imports import *
class WriteHeatEquationTemplate(Scene):
CONFIG = {
"tex_mobject_config": {
"tex_to_color_map": {
"{T}": WHITE,
"{t}": YELLOW,
"{x}": GREEN,
"{y}": RED,
"{z}": BLUE,
"\\partial": WHITE,
"2": WHITE,
},
},
}
def get_d1_equation(self):
return TexMobject(
"{\\partial {T} \\over \\partial {t}}({x}, {t})", "=",
"\\alpha \\cdot",
"{\\partial^2 {T} \\over \\partial {x}^2} ({x}, {t})",
**self.tex_mobject_config
)
def get_d1_equation_without_inputs(self):
return TexMobject(
"{\\partial {T} \\over \\partial {t}}", "=",
"\\alpha \\cdot",
"{\\partial^2 {T} \\over \\partial {x}^2}",
**self.tex_mobject_config
)
def get_d3_equation(self):
return TexMobject(
"{\\partial {T} \\over \\partial {t}}", "=",
"\\alpha \\left(",
"{\\partial^2 {T} \\over \\partial {x}^2} + ",
"{\\partial^2 {T} \\over \\partial {y}^2} + ",
"{\\partial^2 {T} \\over \\partial {z}^2}",
"\\right)",
**self.tex_mobject_config
)
def get_general_equation(self):
return TexMobject(
"{\\partial {T} \\over \\partial {t}}", "=",
"\\alpha", "\\nabla^2 {T}",
**self.tex_mobject_config,
)
def get_d3_equation_with_inputs(self):
return TexMobject(
"{\\partial {T} \\over \\partial {t}}",
"({x}, {y}, {z}, {t})", "=",
"\\alpha \\left(",
"{\\partial^2 {T} \\over \\partial {x}^2}",
"({x}, {y}, {z}, {t}) + ",
"{\\partial^2 {T} \\over \\partial {y}^2}",
"({x}, {y}, {z}, {t}) + ",
"{\\partial^2 {T} \\over \\partial {z}^2}",
"({x}, {y}, {z}, {t})",
"\\right)",
**self.tex_mobject_config
)
def get_d1_words(self):
return TextMobject("Heat equation\\\\", "(1 dimension)")
def get_d3_words(self):
return TextMobject("Heat equation\\\\", "(3 dimensions)")
def get_d1_group(self):
group = VGroup(
self.get_d1_words(),
self.get_d1_equation(),
)
group.arrange(DOWN, buff=MED_LARGE_BUFF)
return group
def get_d3_group(self):
group = VGroup(
self.get_d3_words(),
self.get_d3_equation(),
)
group.arrange(DOWN, buff=MED_LARGE_BUFF)
return group
class HeatEquationIntroTitle(WriteHeatEquationTemplate):
def construct(self):
scale_factor = 1.25
title = TextMobject("The Heat Equation")
title.scale(scale_factor)
title.to_edge(UP)
equation = self.get_general_equation()
equation.scale(scale_factor)
equation.next_to(title, DOWN, MED_LARGE_BUFF)
equation.set_color_by_tex("{T}", RED)
self.play(
FadeInFrom(title, DOWN),
FadeInFrom(equation, UP),
)
self.wait()
class BringTogether(Scene):
def construct(self):
arrows = VGroup(Vector(2 * RIGHT), Vector(2 * LEFT))
arrows.arrange(RIGHT, buff=2)
words = TextMobject("Bring together")[0]
words.next_to(arrows, DOWN)
words.save_state()
words.space_out_submobjects(1.2)
self.play(
VFadeIn(words),
Restore(words),
arrows.arrange, RIGHT, {"buff": SMALL_BUFF},
VFadeIn(arrows),
)
self.play(FadeOut(words), FadeOut(arrows))
class FourierSeriesIntro(WriteHeatEquationTemplate):
def construct(self):
title_scale_value = 1.5
title = TextMobject(
"Fourier ", "Series",
)
title.scale(title_scale_value)
title.to_edge(UP)
title.generate_target()
details_coming = TextMobject("Details coming...")
details_coming.next_to(title.get_corner(DR), DOWN)
details_coming.set_color(LIGHT_GREY)
# physics = TextMobject("Physics")
heat = TextMobject("Heat")
heat.scale(title_scale_value)
physics = self.get_general_equation()
physics.set_color_by_tex("{T}", RED)
arrow1 = Arrow(LEFT, RIGHT)
arrow2 = Arrow(LEFT, RIGHT)
group = VGroup(
heat, arrow1, physics, arrow2, title.target
)
group.arrange(RIGHT)
# physics.align_to(title.target, UP)
group.to_edge(UP)
rot_square = Square()
rot_square.fade(1)
rot_square.add_updater(lambda m, dt: m.rotate(dt))
def update_heat_colors(heat):
colors = [YELLOW, RED]
vertices = rot_square.get_vertices()
letters = heat.family_members_with_points()
for letter, vertex in zip(letters, vertices):
alpha = (normalize(vertex)[0] + 1) / 2
i, sa = integer_interpolate(0, len(colors) - 1, alpha)
letter.set_color(interpolate_color(
colors[i], colors[i + 1], alpha,
))
heat.add_updater(update_heat_colors)
image = ImageMobject("Joseph Fourier")
image.set_height(5)
image.next_to(title, DOWN, LARGE_BUFF)
image.to_edge(LEFT)
name = TextMobject("Joseph", "Fourier")
name.next_to(image, DOWN)
bubble = ThoughtBubble(
height=2,
width=2.5,
direction=RIGHT,
)
bubble.set_fill(opacity=0)
bubble.set_stroke(WHITE)
bubble.set_stroke(BLACK, 5, background=True)
bubble.shift(heat.get_center() - bubble.get_bubble_center())
bubble[:-1].shift(LEFT + 0.2 * DOWN)
bubble[:-1].rotate(-20 * DEGREES)
for mob in bubble[:-1]:
mob.rotate(20 * DEGREES)
# self.play(FadeInFromDown(title))
self.add(title)
self.play(
FadeInFromDown(image),
TransformFromCopy(
title.get_part_by_tex("Fourier"),
name.get_part_by_tex("Fourier"),
path_arc=90 * DEGREES,
),
FadeIn(name.get_part_by_tex("Joseph")),
)
self.play(Write(details_coming, run_time=1))
self.play(LaggedStartMap(FadeOut, details_coming[0], run_time=1))
self.wait()
self.add(rot_square)
self.play(
FadeInFrom(physics, RIGHT),
GrowArrow(arrow2),
FadeInFrom(heat, RIGHT),
GrowArrow(arrow1),
MoveToTarget(title),
)
self.play(ShowCreation(bubble))
self.wait(10)
class CompareODEToPDE(Scene):
def construct(self):
pass
class TodaysTargetWrapper(Scene):
def construct(self):
pass
class TwoGraphTypeTitles(Scene):
def construct(self):
left_title = TextMobject(
"Represent time\\\\with actual time"
)
left_title.shift(FRAME_WIDTH * LEFT / 4)
right_title = TextMobject(
"Represent time\\\\with an axis"
)
right_title.shift(FRAME_WIDTH * RIGHT / 4)
titles = VGroup(left_title, right_title)
for title in titles:
title.scale(1.25)
title.to_edge(UP)
self.play(FadeInFromDown(right_title))
self.wait()
self.play(FadeInFromDown(left_title))
self.wait()
class ShowPartialDerivativeSymbols(Scene):
def construct(self):
t2c = {
"{x}": GREEN,
"{t}": YELLOW,
}
d_derivs, del_derivs = VGroup(*[
VGroup(*[
TexMobject(
"{" + sym, "T", "\\over", sym, var + "}",
"(", "{x}", ",", "{t}", ")",
).set_color_by_tex_to_color_map(t2c)
for var in ("{x}", "{t}")
])
for sym in ("d", "\\partial")
])
dTdx, dTdt = d_derivs
delTdelx, delTdelx = del_derivs
dels = VGroup(*it.chain(*[
del_deriv.get_parts_by_tex("\\partial")
for del_deriv in del_derivs
]))
dTdx.to_edge(UP)
self.play(FadeInFrom(dTdx, DOWN))
self.wait()
self.play(ShowCreationThenFadeAround(dTdx[3:5]))
self.play(ShowCreationThenFadeAround(dTdx[:2]))
self.wait()
dTdt.move_to(dTdx)
self.play(
dTdx.next_to, dTdt, RIGHT, {"buff": 1.5},
dTdx.set_opacity, 0.5,
FadeInFromDown(dTdt)
)
self.wait()
for m1, m2 in zip(d_derivs, del_derivs):
m2.move_to(m1)
pd_words = TextMobject("Partial derivatives")
pd_words.next_to(del_derivs, DOWN, MED_LARGE_BUFF)
self.play(
Write(pd_words),
dTdx.set_opacity, 1,
run_time=1,
)
self.wait()
self.play(
ReplacementTransform(d_derivs, del_derivs)
)
self.play(
LaggedStartMap(
ShowCreationThenFadeAround,
dels,
surrounding_rectangle_config={
"color": BLUE,
"buff": 0.5 * SMALL_BUFF,
"stroke_width": 2,
}
)
)
self.wait()
num_words = VGroup(*[
TextMobject(
"Change in $T$\\\\caused by {}",
"$\\partial$", "${}$".format(var),
arg_separator="",
).set_color_by_tex_to_color_map(t2c)
for var in ("{x}", "{t}")
])
num_words.scale(0.8)
for word, deriv in zip(num_words, del_derivs):
num = deriv[:2]
word.move_to(num, UP)
word.to_edge(UP, buff=MED_SMALL_BUFF)
deriv.rect = SurroundingRectangle(
num,
buff=SMALL_BUFF,
stroke_width=2,
color=word[-1].get_color(),
)
deriv.rect.mob = num
deriv.rect.add_updater(lambda r: r.move_to(r.mob))
self.play(
Write(num_words[1]),
VGroup(del_derivs, pd_words).shift, DOWN,
ShowCreation(del_derivs[1].rect),
)
self.play(
Write(num_words[0]),
ShowCreation(del_derivs[0].rect),
)
self.wait()
class WriteHeatEquation(WriteHeatEquationTemplate):
def construct(self):
title = TextMobject("The Heat Equation")
title.to_edge(UP)
equation = self.get_d1_equation()
equation.next_to(title, DOWN)
eq_i = equation.index_of_part_by_tex("=")
dt_part = equation[:eq_i]
dx_part = equation[eq_i + 3:]
dt_rect = SurroundingRectangle(dt_part)
dt_rect.set_stroke(YELLOW, 2)
dx_rect = SurroundingRectangle(dx_part)
dx_rect.set_stroke(GREEN, 2)
two_outlines = equation.get_parts_by_tex("2").copy()
two_outlines.set_stroke(YELLOW, 2)
two_outlines.set_fill(opacity=0)
to_be_explained = TextMobject(
"To be explained shortly..."
)
to_be_explained.scale(0.7)
to_be_explained.next_to(equation, RIGHT, MED_LARGE_BUFF)
to_be_explained.fade(1)
pde = TextMobject("Partial Differential Equation")
pde.move_to(title)
del_outlines = equation.get_parts_by_tex("\\partial").copy()
del_outlines.set_stroke(YELLOW, 2)
del_outlines.set_fill(opacity=0)
self.play(
FadeInFrom(title, 0.5 * DOWN),
FadeInFrom(equation, 0.5 * UP),
)
self.wait()
self.play(ShowCreation(dt_rect))
self.wait()
self.play(TransformFromCopy(dt_rect, dx_rect))
self.play(ShowCreationThenDestruction(two_outlines))
self.wait()
self.play(Write(to_be_explained, run_time=1))
self.wait(2)
self.play(
ShowCreationThenDestruction(
del_outlines,
lag_ratio=0.1,
)
)
self.play(
FadeOutAndShift(title, UP),
FadeInFrom(pde, DOWN),
FadeOut(dt_rect),
FadeOut(dx_rect),
)
self.wait()
class Show3DEquation(WriteHeatEquationTemplate):
def construct(self):
equation = self.get_d3_equation_with_inputs()
equation.set_width(FRAME_WIDTH - 1)
inputs = VGroup(*it.chain(*[
equation.get_parts_by_tex(s)
for s in ["{x}", "{y}", "{z}", "{t}"]
]))
inputs.sort()
equation.to_edge(UP)
self.add(equation)
self.play(LaggedStartMap(
ShowCreationThenFadeAround, inputs,
surrounding_rectangle_config={
"buff": 0.05,
"stroke_width": 2,
}
))
self.wait()
class Show1DAnd3DEquations(WriteHeatEquationTemplate):
def construct(self):
d1_group = self.get_d1_group()
d3_group = self.get_d3_group()
d1_words, d1_equation = d1_group
d3_words, d3_equation = d3_group
groups = VGroup(d1_group, d3_group)
for group in groups:
group.arrange(DOWN, buff=MED_LARGE_BUFF)
groups.arrange(RIGHT, buff=1.5)
groups.to_edge(UP)
d3_rhs = d3_equation[9:-2]
d3_brace = Brace(d3_rhs, DOWN)
nabla_words = TextMobject("Sometimes written as")
nabla_words.match_width(d3_brace)
nabla_words.next_to(d3_brace, DOWN)
nabla_exp = TexMobject(
"\\nabla^2 {T}",
**self.tex_mobject_config,
)
nabla_exp.next_to(nabla_words, DOWN)
# nabla_group = VGroup(nabla_words, nabla_exp)
d1_group.save_state()
d1_group.center().to_edge(UP)
self.play(
Write(d1_words),
FadeInFrom(d1_equation, UP),
run_time=1,
)
self.wait(2)
self.play(
Restore(d1_group),
FadeInFrom(d3_group, LEFT)
)
self.wait()
self.play(
GrowFromCenter(d3_brace),
Write(nabla_words),
TransformFromCopy(d3_rhs, nabla_exp),
run_time=1,
)
self.wait()
class D1EquationNoInputs(WriteHeatEquationTemplate):
def construct(self):
equation = self.get_d1_equation_without_inputs()
equation.to_edge(UP)
# i1 = equation.index_of_part_by_tex("\\partial")
# i2 = equation.index_of_part_by_tex("\\cdot")
# equation[i1:i1 + 2].set_color(RED)
# equation[i2 + 1:i2 + 6].set_color(RED)
equation.set_color_by_tex("{T}", RED)
self.add(equation)
class AltHeatRHS(Scene):
def construct(self):
formula = TexMobject(
"{\\alpha \\over 2}", "\\Big(",
"T({x} - 1, {t}) + T({x} + 1, {t})"
"\\Big)",
tex_to_color_map={
"{x}": GREEN,
"{t}": YELLOW,
}
)
self.add(formula)
class CompareInputsOfGeneralCaseTo1D(WriteHeatEquation):
def construct(self):
three_d_expr, one_d_expr = [
TexMobject(
"{T}(" + inputs + ", {t})",
**self.tex_mobject_config,
)
for inputs in ["{x}, {y}, {z}", "{x}"]
]
for expr in three_d_expr, one_d_expr:
expr.scale(2)
expr.to_edge(UP)
x, y, z = [
three_d_expr.get_part_by_tex(letter)
for letter in ["x", "y", "z"]
]
self.play(FadeInFromDown(three_d_expr))
self.play(LaggedStartMap(
ShowCreationThenFadeAround,
VGroup(x, y, z)
))
self.wait()
low = 3
high = -3
self.play(
ReplacementTransform(three_d_expr[:low], one_d_expr[:low]),
ReplacementTransform(three_d_expr[high:], one_d_expr[high:]),
three_d_expr[low:high].scale, 0,
)
self.wait()
class ShowLaplacian(WriteHeatEquation):
def construct(self):
equation = self.get_d3_equation()
equation.to_edge(UP, buff=MED_SMALL_BUFF)
parts = VGroup()
plusses = VGroup()
for char in "xyz":
index = equation.index_of_part_by_tex(
"{" + char + "}"
)
part = equation[index - 6:index + 3]
rect = SurroundingRectangle(part)
rect.match_color(equation[index])
parts.add(part)
part.rect = rect
if char in "yz":
plus = equation[index - 8]
part.plus = plus
plusses.add(plus)
lp = equation.get_part_by_tex("(")
rp = equation.get_part_by_tex(")")
for part in parts:
part.rp = rp.copy()
part.rp.next_to(part, RIGHT, SMALL_BUFF)
part.rp.align_to(lp, UP)
rp.become(parts[0].rp)
# Show new second derivatives
self.add(*equation)
self.remove(*plusses, *parts[1], *parts[2])
for part in parts[1:]:
self.play(
rp.become, part.rp,
FadeInFrom(part, LEFT),
Write(part.plus),
ShowCreation(part.rect),
)
self.play(
FadeOut(part.rect),
)
self.wait()
# Show laplacian
brace = Brace(parts, DOWN)
laplacian = TexMobject("\\nabla^2", "T")
laplacian.next_to(brace, DOWN)
laplacian_name = TextMobject(
"``Laplacian''"
)
laplacian_name.next_to(laplacian, DOWN)
T_parts = VGroup(*[part[3] for part in parts])
non_T_parts = VGroup(*[
VGroup(*part[:3], *part[4:])
for part in parts
])
self.play(GrowFromCenter(brace))
self.play(Write(laplacian_name))
self.play(
TransformFromCopy(non_T_parts, laplacian[0])
)
self.play(
TransformFromCopy(T_parts, laplacian[1])
)
self.wait(3)
class AskAboutActuallySolving(WriteHeatEquationTemplate):
def construct(self):
equation = self.get_d1_equation()
equation.center()
q1 = TextMobject("Solve for T?")
q1.next_to(equation, UP, LARGE_BUFF)
q2 = TextMobject("What does it \\emph{mean} to solve this?")
q2.next_to(equation, UP, LARGE_BUFF)
formula = TexMobject(
"T({x}, {t}) = \\sin\\big(a{x}\\big) e^{-\\alpha \\cdot a^2 {t}}",
tex_to_color_map={
"{x}": GREEN,
"{t}": YELLOW,
}
)
formula.next_to(equation, DOWN, LARGE_BUFF)
q3 = TextMobject("Is this it?")
arrow = Vector(LEFT, color=WHITE)
arrow.next_to(formula, RIGHT)
q3.next_to(arrow, RIGHT)
self.add(equation)
self.play(FadeInFromDown(q1))
self.wait()
self.play(
FadeInFromDown(q2),
q1.shift, 1.5 * UP,
)
self.play(FadeInFrom(formula, UP))
self.play(
GrowArrow(arrow),
FadeInFrom(q3, LEFT)
)
self.wait()
class PDEPatreonEndscreen(PatreonEndScreen):
CONFIG = {
"specific_patrons": [
"Juan Benet",
"Vassili Philippov",
"Burt Humburg",
"Matt Russell",
"Scott Gray",
"soekul",
"Tihan Seale",
"Richard Barthel",
"Ali Yahya",
"dave nicponski",
"Evan Phillips",
"Graham",
"Joseph Kelly",
"Kaustuv DeBiswas",
"LambdaLabs",
"Lukas Biewald",
"Mike Coleman",
"Peter Mcinerney",
"Quantopian",
"Roy Larson",
"Scott Walter, Ph.D.",
"Yana Chernobilsky",
"Yu Jun",
"Jordan Scales",
"D. Sivakumar",
"Lukas -krtek.net- Novy",
"John Shaughnessy",
"Britt Selvitelle",
"David Gow",
"J",
"Jonathan Wilson",
"Joseph John Cox",
"Magnus Dahlström",
"Randy C. Will",
"Ryan Atallah",
"Luc Ritchie",
"1stViewMaths",
"Adrian Robinson",
"Alexis Olson",
"Andreas Benjamin Brössel",
"Andrew Busey",
"Ankalagon",
"Antoine Bruguier",
"Antonio Juarez",
"Arjun Chakroborty",
"Art Ianuzzi",
"Awoo",
"Bernd Sing",
"Boris Veselinovich",
"Brian Staroselsky",
"Chad Hurst",
"Charles Southerland",
"Chris Connett",
"Christian Kaiser",
"Clark Gaebel",
"Cooper Jones",
"Danger Dai",
"Dave B",
"Dave Kester",
"David B. Hill",
"David Clark",
"DeathByShrimp",
"Delton Ding",
"eaglle",
"emptymachine",
"Eric Younge",
"Eryq Ouithaqueue",
"Federico Lebron",
"Giovanni Filippi",
"Hal Hildebrand",
"Hitoshi Yamauchi",
"Isaac Jeffrey Lee",
"j eduardo perez",
"Jacob Magnuson",
"Jameel Syed",
"Jason Hise",
"Jeff Linse",
"Jeff Straathof",
"John Griffith",
"John Haley",
"John V Wertheim",
"Jonathan Eppele",
"Kai-Siang Ang",
"Kanan Gill",
"L0j1k",
"Lee Beck",
"Lee Redden",
"Linh Tran",
"Ludwig Schubert",
"Magister Mugit",
"Mark B Bahu",
"Mark Heising",
"Martin Price",
"Mathias Jansson",
"Matt Langford",
"Matt Roveto",
"Matthew Bouchard",
"Matthew Cocke",
"Michael Faust",
"Michael Hardel",
"Mirik Gogri",
"Mustafa Mahdi",
"Márton Vaitkus",
"Nero Li",
"Nikita Lesnikov",
"Omar Zrien",
"Owen Campbell-Moore",
"Peter Ehrnstrom",
"RedAgent14",
"rehmi post",
"Richard Burgmann",
"Richard Comish",
"Ripta Pasay",
"Rish Kundalia",
"Robert Teed",
"Roobie",
"Ryan Williams",
"Sachit Nagpal",
"Solara570",
"Stevie Metke",
"Tal Einav",
"Ted Suzman",
"Thomas Tarler",
"Tom Fleming",
"Valeriy Skobelev",
"Xavier Bernard",
"Yavor Ivanov",
"Yaw Etse",
"YinYangBalance.Asia",
"Zach Cardwell",
],
}

View file

@ -5,7 +5,7 @@ import numpy as np
from manimlib.animation.animation import Animation
from manimlib.constants import DEFAULT_POINTWISE_FUNCTION_RUN_TIME
from manimlib.constants import OUT
from manimlib.constants import PI
from manimlib.constants import DEGREES
from manimlib.mobject.mobject import Group
from manimlib.mobject.mobject import Mobject
from manimlib.utils.config_ops import digest_config
@ -28,12 +28,6 @@ class Transform(Animation):
self.target_mobject = target_mobject
self.init_path_func()
def __str__(self):
return "{}To{}".format(
super().__str__(),
str(self.target_mobject)
)
def init_path_func(self):
if self.path_func is not None:
return
@ -275,7 +269,7 @@ class ApplyComplexFunction(ApplyMethod):
class CyclicReplace(Transform):
CONFIG = {
"path_arc": PI / 2,
"path_arc": 90 * DEGREES,
}
def __init__(self, *mobjects, **kwargs):

View file

@ -64,8 +64,6 @@ def is_child_scene(obj, module):
return False
if obj == Scene:
return False
if not obj.__module__.startswith(module.__name__):
return False
return True
@ -120,16 +118,13 @@ def get_scenes_to_render(scene_classes, config):
def get_scene_classes_from_module(module):
if hasattr(module, "ALL_SCENE_CLASSES"):
return module.ALL_SCENE_CLASSES
else:
return [
member[1]
for member in inspect.getmembers(
module,
lambda x: is_child_scene(x, module)
)
]
return [
member[1]
for member in inspect.getmembers(
module,
lambda x: is_child_scene(x, module)
)
]
def main(config):

View file

@ -239,14 +239,11 @@ class PatreonEndScreen(PatreonThanks, PiCreatureScene):
if columns.get_width() > self.max_patron_width:
columns.set_width(total_width - 1)
thanks.to_edge(RIGHT)
columns.next_to(thanks, DOWN, 3 * LARGE_BUFF)
thanks.to_edge(RIGHT, buff=MED_SMALL_BUFF)
columns.next_to(underline, DOWN, buff=2)
columns.generate_target()
columns.target.move_to(2 * DOWN, DOWN)
columns.target.align_to(
thanks, alignment_vect=RIGHT
)
columns.target.to_edge(DOWN, buff=2)
vect = columns.target.get_center() - columns.get_center()
distance = get_norm(vect)
wait_time = 20

View file

@ -3,7 +3,6 @@ import warnings
import numpy as np
from manimlib.animation.transform import Transform
from manimlib.constants import *
from manimlib.mobject.mobject import Mobject
from manimlib.mobject.geometry import Circle
@ -14,6 +13,7 @@ from manimlib.mobject.types.vectorized_mobject import VGroup
from manimlib.mobject.types.vectorized_mobject import VMobject
from manimlib.utils.config_ops import digest_config
from manimlib.utils.space_ops import get_norm
from manimlib.utils.space_ops import normalize
pi_creature_dir_maybe = os.path.join(MEDIA_DIR, "designs", "PiCreature")
if os.path.exists(pi_creature_dir_maybe):
@ -197,10 +197,11 @@ class PiCreature(SVGMobject):
return self
def get_looking_direction(self):
return np.sign(np.round(
self.pupils.get_center() - self.eyes.get_center(),
decimals=2
))
vect = self.pupils.get_center() - self.eyes.get_center()
return normalize(vect)
def get_look_at_spot(self):
return self.eyes.get_center() + self.get_looking_direction()
def is_flipped(self):
return self.eyes.submobjects[0].get_center()[0] > \

View file

@ -1,11 +1,10 @@
import itertools as it
import random
import copy
from manimlib.animation.transform import ApplyMethod
from manimlib.animation.transform import ReplacementTransform
from manimlib.animation.transform import Transform
from manimlib.animation.composition import LaggedStart
from manimlib.animation.update import UpdateFromAlphaFunc
from manimlib.constants import *
from manimlib.for_3b1b_videos.pi_creature import Mortimer
from manimlib.for_3b1b_videos.pi_creature import PiCreature
@ -18,6 +17,7 @@ from manimlib.mobject.svg.drawings import SpeechBubble
from manimlib.mobject.svg.drawings import ThoughtBubble
from manimlib.mobject.types.vectorized_mobject import VGroup
from manimlib.scene.scene import Scene
from manimlib.utils.bezier import interpolate
from manimlib.utils.rate_functions import squish_rate_func
from manimlib.utils.rate_functions import there_and_back
from manimlib.utils.space_ops import get_norm
@ -157,34 +157,31 @@ class PiCreatureScene(Scene):
if not self.any_pi_creatures_on_screen():
return animations
non_pi_creature_anims = [anim for anim in animations if anim.mobject not in self.get_pi_creatures()]
pi_creatures = self.get_on_screen_pi_creatures()
non_pi_creature_anims = [
anim
for anim in animations
if len(set(anim.mobject.get_family()).intersection(pi_creatures)) == 0
]
if len(non_pi_creature_anims) == 0:
return animations
# Look at ending state
# Get pi creatures to look at whatever
# is being animated
first_anim = non_pi_creature_anims[0]
first_anim_copy = copy.deepcopy(first_anim)
first_anim_copy.begin()
first_anim_copy.update(1)
point_of_interest = first_anim_copy.mobject.get_center()
for pi_creature in self.get_pi_creatures():
if pi_creature not in self.get_mobjects():
continue
if pi_creature in first_anim.mobject.get_family():
continue
anims_with_pi_creature = [anim for anim in animations if pi_creature in anim.mobject.get_family()]
for anim in anims_with_pi_creature:
continue # TODO, this is broken
if isinstance(anim, Transform):
index = anim.mobject.get_family().index(pi_creature)
target_family = anim.target_mobject.get_family()
target = target_family[index]
if isinstance(target, PiCreature):
target.look_at(point_of_interest)
if not anims_with_pi_creature:
animations.append(
ApplyMethod(pi_creature.look_at, point_of_interest)
)
main_mobject = first_anim.mobject
animations += [
UpdateFromAlphaFunc(
pi_creature,
lambda p, a: p.look_at(
interpolate(
p.get_look_at_spot(),
main_mobject.get_center(),
a,
)
),
)
for pi_creature in pi_creatures
]
return animations
def blink(self):

View file

@ -34,6 +34,14 @@ class CoordinateSystem():
def point_to_coords(self, point):
raise Exception("Not implemented")
def c2p(self, *coords):
"""Abbreviation for coords_to_point"""
return self.coords_to_point(*coords)
def p2c(self, point):
"""Abbreviation for point_to_coords"""
return self.point_to_coords(point)
def get_axes(self):
raise Exception("Not implemented")
@ -49,6 +57,34 @@ class CoordinateSystem():
def get_z_axis(self):
return self.get_axis(2)
def get_x_axis_label(self, label_tex, edge=RIGHT, direction=DL, **kwargs):
return self.get_axis_label(
label_tex, self.get_x_axis(),
edge, direction, **kwargs
)
def get_y_axis_label(self, label_tex, edge=UP, direction=DR, **kwargs):
return self.get_axis_label(
label_tex, self.get_y_axis(),
edge, direction, **kwargs
)
def get_axis_label(self, label_tex, axis, edge, direction, buff=MED_SMALL_BUFF):
label = TexMobject(label_tex)
label.next_to(
axis.get_edge_center(edge), direction,
buff=buff
)
label.shift_onto_screen(buff=MED_SMALL_BUFF)
return label
def get_axis_labels(self, x_label_tex="x", y_label_tex="y"):
self.axis_labels = VGroup(
self.get_x_axis_label(x_label_tex),
self.get_y_axis_label(y_label_tex),
)
return self.axis_labels
def get_graph(self, function, **kwargs):
x_min = kwargs.pop("x_min", self.x_min)
x_max = kwargs.pop("x_max", self.x_max)
@ -318,34 +354,6 @@ class NumberPlane(Axes):
def get_axes(self):
return self.axes
def get_x_axis_label(self, label_tex, edge=RIGHT, direction=DL, **kwargs):
return self.get_axis_label(
label_tex, self.get_x_axis(),
edge, direction, **kwargs
)
def get_y_axis_label(self, label_tex, edge=UP, direction=DR, **kwargs):
return self.get_axis_label(
label_tex, self.get_y_axis(),
edge, direction, **kwargs
)
def get_axis_label(self, label_tex, axis, edge, direction, buff=MED_SMALL_BUFF):
label = TexMobject(label_tex)
label.next_to(
axis.get_edge_center(edge), direction,
buff=buff
)
label.shift_onto_screen(buff=MED_SMALL_BUFF)
return label
def get_axis_labels(self, x_label_tex="x", y_label_tex="y"):
self.axis_labels = VGroup(
self.get_x_axis_label(x_label_tex),
self.get_y_axis_label(y_label_tex),
)
return self.axis_labels
def get_vector(self, coords, **kwargs):
kwargs["buff"] = 0
return Arrow(

View file

@ -139,8 +139,8 @@ class TipableVMobject(VMobject):
return VMobject.get_start(self)
def get_length(self):
start, end = self.get_start_and_end()
return get_norm(start - end)
start, end = self.get_start_and_end()
return get_norm(start - end)
def has_tip(self):
return hasattr(self, "tip") and self.tip in self
@ -385,7 +385,7 @@ class Line(TipableVMobject):
"path_arc": None, # angle of arc specified here
}
def __init__(self, start, end, **kwargs):
def __init__(self, start=LEFT, end=RIGHT, **kwargs):
digest_config(self, kwargs)
self.set_start_and_end_attrs(start, end)
VMobject.__init__(self, **kwargs)
@ -443,6 +443,16 @@ class Line(TipableVMobject):
return mob.get_boundary_point(direction)
return np.array(mob_or_point)
def put_start_and_end_on(self, start, end):
curr_start, curr_end = self.get_start_and_end()
if np.all(curr_start == curr_end):
# TODO, any problems with resetting
# these attrs?
self.start = start
self.end = end
self.generate_points()
super().put_start_and_end_on(start, end)
def get_vector(self):
return self.get_end() - self.get_start()
@ -541,9 +551,8 @@ class Arrow(Line):
CONFIG = {
"stroke_width": 6,
"buff": MED_SMALL_BUFF,
"tip_width_to_length_ratio": 1,
"max_tip_length_to_length_ratio": 0.25,
"max_stroke_width_to_length_ratio": 4,
"max_stroke_width_to_length_ratio": 5,
"preserve_tip_size_when_scaling": True,
"rectangular_stem_width": 0.05,
}
@ -568,12 +577,19 @@ class Arrow(Line):
VMobject.scale(self, factor, **kwargs)
self.set_stroke_width_from_length()
# So horribly confusing, must redo
if has_tip:
self.add_tip()
self.tip.match_style(old_tips[0])
old_tips[0].points[:, :] = self.tip.points
self.remove(self.tip)
self.tip = old_tips[0]
self.add(self.tip)
if has_start_tip:
self.add_tip(at_start=True)
self.start_tip.match_style(old_tips[1])
old_tips[1].points[:, :] = self.start_tip.points
self.remove(self.start_tip)
self.start_tip = old_tips[1]
self.add(self.start_tip)
return self
def get_normal_vector(self):
@ -613,7 +629,7 @@ class Vector(Arrow):
"buff": 0,
}
def __init__(self, direction, **kwargs):
def __init__(self, direction=RIGHT, **kwargs):
if len(direction) == 2:
direction = np.append(np.array(direction), 0)
Arrow.__init__(self, ORIGIN, direction, **kwargs)

View file

@ -173,6 +173,12 @@ class Mobject(Container):
def get_updaters(self):
return self.updaters
def get_family_updaters(self):
return list(it.chain(*[
sm.get_updaters()
for sm in self.get_family()
]))
def add_updater(self, update_function, index=None, call_updater=True):
if index is None:
self.updaters.append(update_function)
@ -194,6 +200,12 @@ class Mobject(Container):
submob.clear_updaters()
return self
def match_updaters(self, mobject):
self.clear_updaters()
for updater in mobject.get_updaters():
self.add_updater(updater)
return self
def suspend_updating(self, recursive=True):
self.updating_suspended = True
if recursive:

View file

@ -122,6 +122,14 @@ class NumberLine(Line):
)
return interpolate(self.x_min, self.x_max, proportion)
def n2p(self, number):
"""Abbreviation for number_to_point"""
return self.number_to_point(number)
def p2n(self, point):
"""Abbreviation for point_to_number"""
return self.point_to_number(point)
def get_unit_size(self):
return (self.x_max - self.x_min) / self.get_length()

View file

@ -132,14 +132,14 @@ class DecimalNumber(VMobject):
def get_value(self):
return self.number
def increment_value(self, delta_t=1):
self.set_value(self.get_value() + delta_t)
class Integer(DecimalNumber):
CONFIG = {
"num_decimal_places": 0,
}
def increment_value(self):
self.set_value(self.get_value() + 1)
def get_value(self):
return int(np.round(super().get_value()))

View file

@ -1,4 +1,5 @@
import itertools as it
import string
from manimlib.animation.animation import Animation
from manimlib.animation.rotation import Rotating
@ -349,7 +350,7 @@ class Clock(VGroup):
CONFIG = {}
def __init__(self, **kwargs):
circle = Circle()
circle = Circle(color=WHITE)
ticks = []
for x in range(12):
alpha = x / 12.
@ -832,10 +833,7 @@ class Logo(VMobject):
return blue_part, brown_part
# Cards
class DeckOfCards(VGroup):
def __init__(self, **kwargs):
possible_values = list(map(str, list(range(1, 11)))) + ["J", "Q", "K"]

View file

@ -552,7 +552,7 @@ class GraphScene(Scene):
kwargs["dx"] = dx
kwargs["x"] = x
new_group = self.get_secant_slope_group(**kwargs)
Transform(group, new_group).update(1)
group.become(new_group)
return group
self.play(

View file

@ -288,7 +288,7 @@ class Scene(Container):
for i, mob in enumerate(mobjects):
update_possibilities = [
mob in animation_mobjects,
len(mob.get_updaters()) > 0,
len(mob.get_family_updaters()) > 0,
mob in self.foreground_mobjects
]
if any(update_possibilities):
@ -493,13 +493,15 @@ class Scene(Container):
@handle_play_like_call
def wait(self, duration=DEFAULT_WAIT_TIME, stop_condition=None):
dt = 1 / self.camera.frame_rate
self.update_mobjects(dt=0) # Any problems with this?
if self.should_update_mobjects():
time_progression = self.get_wait_time_progression(duration, stop_condition)
# TODO, be smart about setting a static image
# the same way Scene.play does
last_t = 0
for t in time_progression:
dt = t - last_t
last_t = t
self.update_mobjects(dt)
self.update_frame()
self.add_frames(self.get_frame())
@ -511,6 +513,7 @@ class Scene(Container):
return self
else:
self.update_frame()
dt = 1 / self.camera.frame_rate
n_frames = int(duration / dt)
frame = self.get_frame()
self.add_frames(*[frame] * n_frames)

View file

@ -7,7 +7,7 @@ from old_projects.clacks.solution2 import simple_scenes
from old_projects.clacks.solution2 import wordy_scenes
OUTPUT_DIRECTORY = "clacks/solution2"
ALL_SCENE_CLASSES = [
SCENES_IN_ORDER = [
question.NameIntro,
block_collision_scenes.IntroducePreviousTwoVideos,
block_collision_scenes.PreviousTwoVideos,

View file

@ -12,8 +12,8 @@ from manimlib.extract_scene import is_child_scene
def get_sorted_scene_classes(module_name):
module = get_module(module_name)
if hasattr(module, "ALL_SCENE_CLASSES"):
return module.ALL_SCENE_CLASSES
if hasattr(module, "SCENES_IN_ORDER"):
return module.SCENES_IN_ORDER
# Otherwise, deduce from the order in which
# they're defined in a file
importlib.import_module(module.__name__)
@ -43,7 +43,7 @@ def stage_scenes(module_name):
# }
# TODO, fix this
animation_dir = os.path.join(
VIDEO_DIR, "ode", "part1", "1440p60"
VIDEO_DIR, "ode", "part2", "1440p60"
)
#
files = os.listdir(animation_dir)