mirror of
https://github.com/3b1b/manim.git
synced 2025-08-21 05:44:04 +00:00
Preliminarily done with Chapter 10 animations
This commit is contained in:
parent
2de817010d
commit
2ec1db94d0
9 changed files with 1764 additions and 57 deletions
|
@ -68,7 +68,7 @@ class Write(ShowCreation):
|
||||||
if "run_time" not in kwargs:
|
if "run_time" not in kwargs:
|
||||||
self.establish_run_time(mobject)
|
self.establish_run_time(mobject)
|
||||||
if "lag_factor" not in kwargs:
|
if "lag_factor" not in kwargs:
|
||||||
self.lag_factor = self.run_time - 1
|
self.lag_factor = max(self.run_time - 1, 1)
|
||||||
ShowCreation.__init__(self, mobject, **kwargs)
|
ShowCreation.__init__(self, mobject, **kwargs)
|
||||||
|
|
||||||
def establish_run_time(self, mobject):
|
def establish_run_time(self, mobject):
|
||||||
|
|
1695
eola/chapter10.py
1695
eola/chapter10.py
File diff suppressed because it is too large
Load diff
|
@ -1083,12 +1083,14 @@ class MatrixVectorMultiplicationAbstract(MatrixVectorMultiplication):
|
||||||
}
|
}
|
||||||
|
|
||||||
class ColumnsToBasisVectors(LinearTransformationScene):
|
class ColumnsToBasisVectors(LinearTransformationScene):
|
||||||
|
CONFIG = {
|
||||||
|
"t_matrix" : [[3, 1], [1, 2]]
|
||||||
|
}
|
||||||
def construct(self):
|
def construct(self):
|
||||||
self.setup()
|
self.setup()
|
||||||
transposed_matrix = [[3, 1], [1, 2]]
|
|
||||||
vector_coords = [-1, 2]
|
vector_coords = [-1, 2]
|
||||||
|
|
||||||
vector = self.move_matrix_columns(transposed_matrix, vector_coords)
|
vector = self.move_matrix_columns(self.t_matrix, vector_coords)
|
||||||
self.scale_and_add(vector, vector_coords)
|
self.scale_and_add(vector, vector_coords)
|
||||||
self.dither(3)
|
self.dither(3)
|
||||||
|
|
||||||
|
@ -1096,6 +1098,7 @@ class ColumnsToBasisVectors(LinearTransformationScene):
|
||||||
matrix = np.array(transposed_matrix).transpose()
|
matrix = np.array(transposed_matrix).transpose()
|
||||||
matrix_mob = Matrix(matrix)
|
matrix_mob = Matrix(matrix)
|
||||||
matrix_mob.to_corner(UP+LEFT)
|
matrix_mob.to_corner(UP+LEFT)
|
||||||
|
matrix_mob.add_background_to_entries()
|
||||||
col1 = VMobject(*matrix_mob.get_mob_matrix()[:,0])
|
col1 = VMobject(*matrix_mob.get_mob_matrix()[:,0])
|
||||||
col1.highlight(X_COLOR)
|
col1.highlight(X_COLOR)
|
||||||
col2 = VMobject(*matrix_mob.get_mob_matrix()[:,1])
|
col2 = VMobject(*matrix_mob.get_mob_matrix()[:,1])
|
||||||
|
|
|
@ -48,8 +48,8 @@ def vector_coordinate_label(vector_mob, integer_labels = True,
|
||||||
shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER*RIGHT
|
shift_dir -= label.get_right() + DEFAULT_MOBJECT_TO_MOBJECT_BUFFER*RIGHT
|
||||||
label.shift(shift_dir)
|
label.shift(shift_dir)
|
||||||
label.highlight(color)
|
label.highlight(color)
|
||||||
background = BackgroundRectangle(label)
|
label.rect = BackgroundRectangle(label)
|
||||||
label.submobjects = [background] + label.submobjects
|
label.add_to_back(label.rect)
|
||||||
return label
|
return label
|
||||||
|
|
||||||
class Matrix(VMobject):
|
class Matrix(VMobject):
|
||||||
|
|
|
@ -394,6 +394,9 @@ class LinearTransformationScene(VectorScene):
|
||||||
def get_vector_movement(self, func):
|
def get_vector_movement(self, func):
|
||||||
for v in self.moving_vectors:
|
for v in self.moving_vectors:
|
||||||
v.target = Vector(func(v.get_end()), color = v.get_color())
|
v.target = Vector(func(v.get_end()), color = v.get_color())
|
||||||
|
norm = np.linalg.norm(v.target.get_end())
|
||||||
|
if norm < 0.1:
|
||||||
|
v.target.get_tip().scale_in_place(norm)
|
||||||
return self.get_piece_movement(self.moving_vectors)
|
return self.get_piece_movement(self.moving_vectors)
|
||||||
|
|
||||||
def get_transformable_label_movement(self):
|
def get_transformable_label_movement(self):
|
||||||
|
|
|
@ -200,6 +200,7 @@ class VMobject(Mobject):
|
||||||
it comes time to display.
|
it comes time to display.
|
||||||
"""
|
"""
|
||||||
subpath_mobject = self.copy()#TODO, better way?
|
subpath_mobject = self.copy()#TODO, better way?
|
||||||
|
# subpath_mobject = VMobject()
|
||||||
subpath_mobject.is_subpath = True
|
subpath_mobject.is_subpath = True
|
||||||
subpath_mobject.set_points(points)
|
subpath_mobject.set_points(points)
|
||||||
self.add(subpath_mobject)
|
self.add(subpath_mobject)
|
||||||
|
|
|
@ -248,8 +248,8 @@ class Bubble(SVGMobject):
|
||||||
self.content = mobject
|
self.content = mobject
|
||||||
return self.content
|
return self.content
|
||||||
|
|
||||||
def write(self, text):
|
def write(self, *text):
|
||||||
self.add_content(TextMobject(text))
|
self.add_content(TextMobject(*text))
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def clear(self):
|
def clear(self):
|
||||||
|
@ -414,15 +414,19 @@ class TeacherStudentsScene(Scene):
|
||||||
self.play(Blink(pi_creature))
|
self.play(Blink(pi_creature))
|
||||||
self.dither()
|
self.dither()
|
||||||
|
|
||||||
def change_student_modes(self, *modes):
|
def change_student_modes(self, *modes, **kwargs):
|
||||||
|
added_anims = kwargs.get("added_anims", [])
|
||||||
pairs = zip(self.get_students(), modes)
|
pairs = zip(self.get_students(), modes)
|
||||||
start = VGroup(*[s for s, m in pairs])
|
start = VGroup(*[s for s, m in pairs])
|
||||||
target = VGroup(*[s.copy().change_mode(m) for s, m in pairs])
|
target = VGroup(*[s.copy().change_mode(m) for s, m in pairs])
|
||||||
self.play(Transform(
|
self.play(
|
||||||
|
Transform(
|
||||||
start, target,
|
start, target,
|
||||||
submobject_mode = "lagged_start",
|
submobject_mode = "lagged_start",
|
||||||
run_time = 2
|
run_time = 2
|
||||||
))
|
),
|
||||||
|
*added_anims
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def zoom_in_on_thought_bubble(self, radius = SPACE_HEIGHT+SPACE_WIDTH):
|
def zoom_in_on_thought_bubble(self, radius = SPACE_HEIGHT+SPACE_WIDTH):
|
||||||
|
|
|
@ -203,6 +203,9 @@ class Arrow(Line):
|
||||||
self.add(self.tip)
|
self.add(self.tip)
|
||||||
self.init_colors()
|
self.init_colors()
|
||||||
|
|
||||||
|
def get_tip(self):
|
||||||
|
return self.tip
|
||||||
|
|
||||||
def scale(self, scale_factor):
|
def scale(self, scale_factor):
|
||||||
Line.scale(self, scale_factor)
|
Line.scale(self, scale_factor)
|
||||||
if self.preserve_tip_size_when_scaling:
|
if self.preserve_tip_size_when_scaling:
|
||||||
|
|
|
@ -3,10 +3,9 @@
|
||||||
from mobject.vectorized_mobject import VMobject
|
from mobject.vectorized_mobject import VMobject
|
||||||
from mobject.tex_mobject import TexMobject
|
from mobject.tex_mobject import TexMobject
|
||||||
from animation import Animation
|
from animation import Animation
|
||||||
|
from scene import Scene
|
||||||
from helpers import *
|
from helpers import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class DecimalNumber(VMobject):
|
class DecimalNumber(VMobject):
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"num_decimal_points" : 2,
|
"num_decimal_points" : 2,
|
||||||
|
@ -30,57 +29,66 @@ class DecimalNumber(VMobject):
|
||||||
buff = self.digit_to_digit_buff
|
buff = self.digit_to_digit_buff
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#Todo, this class is now broken
|
||||||
|
|
||||||
|
class RangingValue(Animation):
|
||||||
class RangingValues(Animation):
|
|
||||||
CONFIG = {
|
CONFIG = {
|
||||||
"num_decimal_points" : 2,
|
"num_decimal_points" : 2,
|
||||||
"rate_func" : None,
|
"rate_func" : None,
|
||||||
"tracking_function" : None,
|
|
||||||
"value_function" : None,
|
|
||||||
"tracked_mobject" : None,
|
"tracked_mobject" : None,
|
||||||
"tracked_mobject_next_to_kwargs" : {},
|
"tracked_mobject_next_to_kwargs" : {},
|
||||||
"scale_factor" : None
|
"scale_factor" : None,
|
||||||
|
"color" : WHITE,
|
||||||
}
|
}
|
||||||
def __init__(self, start_val = 0, end_val = 1, **kwargs):
|
def __init__(self, value_function, **kwargs):
|
||||||
|
"""
|
||||||
|
Value function should return a real value
|
||||||
|
depending on the state of the surrounding scene
|
||||||
|
"""
|
||||||
digest_config(self, kwargs, locals())
|
digest_config(self, kwargs, locals())
|
||||||
Animation.__init__(self, self.get_mobject_at_alpha(0), **kwargs)
|
self.update_mobject()
|
||||||
|
Animation.__init__(self, self.mobject, **kwargs)
|
||||||
|
|
||||||
def update_mobject(self, alpha):
|
def update_mobject(self, alpha = 0):
|
||||||
target = self.get_mobject_at_alpha(alpha)
|
mobject = DecimalNumber(
|
||||||
self.mobject.submobjects = target.submobjects
|
self.value_function(),
|
||||||
|
num_decimal_points = self.num_decimal_points,
|
||||||
def get_number(self, alpha):
|
color = self.color,
|
||||||
if self.value_function:
|
|
||||||
return self.value_function(alpha)
|
|
||||||
return interpolate(self.start_val, self.end_val, alpha)
|
|
||||||
|
|
||||||
def get_mobject_at_alpha(self, alpha):
|
|
||||||
mob = DecimalNumber(
|
|
||||||
self.get_number(alpha),
|
|
||||||
num_decimal_points=self.num_decimal_points
|
|
||||||
)
|
)
|
||||||
|
if not hasattr(self, "mobject"):
|
||||||
|
self.mobject = mobject
|
||||||
|
else:
|
||||||
|
self.mobject.points = mobject.points
|
||||||
|
self.mobject.submobjects = mobject.submobjects
|
||||||
if self.scale_factor:
|
if self.scale_factor:
|
||||||
mob.scale(self.scale_factor)
|
self.mobject.scale(self.scale_factor)
|
||||||
if self.tracking_function:
|
|
||||||
self.tracking_function(alpha, mob)
|
|
||||||
elif self.tracked_mobject:
|
elif self.tracked_mobject:
|
||||||
mob.next_to(
|
self.mobject.next_to(
|
||||||
self.tracked_mobject,
|
self.tracked_mobject,
|
||||||
**self.tracked_mobject_next_to_kwargs
|
**self.tracked_mobject_next_to_kwargs
|
||||||
)
|
)
|
||||||
return mob
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
class RangingValueScene(Scene):
|
||||||
|
CONFIG = {
|
||||||
|
"ranging_values" : []
|
||||||
|
}
|
||||||
|
|
||||||
|
def add_ranging_value(self, value_function, **kwargs):
|
||||||
|
self.ranging_values.append(
|
||||||
|
RangingValue(value_function, **kwargs)
|
||||||
|
)
|
||||||
|
|
||||||
|
def update_frame(self, *args, **kwargs):
|
||||||
|
for val in self.ranging_values:
|
||||||
|
self.remove(val.mobject)
|
||||||
|
val.update_mobject()
|
||||||
|
self.add(val.mobject)
|
||||||
|
return Scene.update_frame(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_tracking_function(self, func):
|
|
||||||
"""
|
|
||||||
func shoudl be of the form func(alpha, mobject), and
|
|
||||||
should dictate where to place running number during an
|
|
||||||
animation
|
|
||||||
"""
|
|
||||||
self.tracking_function = func
|
|
||||||
|
|
||||||
def set_value_function(self, func):
|
|
||||||
"""
|
|
||||||
func must be of the form alpha->number
|
|
||||||
"""
|
|
||||||
self.value_function = func
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue