Finished chapter 9

This commit is contained in:
Grant Sanderson
2016-09-10 15:21:03 -07:00
parent 3586231295
commit c2301e282c
7 changed files with 1037 additions and 14 deletions

View File

@ -60,12 +60,15 @@ class Write(ShowCreation):
"submobject_mode" : "lagged_start",
}
def __init__(self, mob_or_text, **kwargs):
digest_config(self, kwargs)
if isinstance(mob_or_text, str):
mobject = TextMobject(mob_or_text)
else:
mobject = mob_or_text
if "run_time" not in kwargs:
if not hasattr(self, "run_time"):
self.establish_run_time(mobject)
if not hasattr(self, "lag_factor"):
self.lag_factor = self.run_time - 1
ShowCreation.__init__(self, mobject, **kwargs)
def establish_run_time(self, mobject):

View File

@ -8,7 +8,7 @@ from helpers import *
from animation import Animation
from simple_animations import DelayByOrder
from mobject import Mobject, Point, VMobject
from mobject import Mobject, Point, VMobject, Group
class Transform(Animation):
CONFIG = {
@ -67,6 +67,21 @@ class MoveToTarget(Transform):
raise Exception("MoveToTarget called on mobject without attribute 'target' ")
Transform.__init__(self, mobject, mobject.target, **kwargs)
class CyclicReplace(Transform):
CONFIG = {
"path_arc" : np.pi/2
}
def __init__(self, *mobjects, **kwargs):
start = Group(*mobjects)
target = Group(*[
m1.copy().move_to(m2)
for m1, m2 in adjascent_pairs(start)
])
Transform.__init__(self, start, target, **kwargs)
class Swap(CyclicReplace):
pass #Renaming, more understandable for two entries
class GrowFromCenter(Transform):
def __init__(self, mobject, **kwargs):
target = mobject.copy()

87
eola/chapter10.py Normal file
View File

@ -0,0 +1,87 @@
from mobject.tex_mobject import TexMobject
from mobject import Mobject
from mobject.image_mobject import ImageMobject
from mobject.vectorized_mobject import VMobject
from animation.animation import Animation
from animation.transform import *
from animation.simple_animations import *
from topics.geometry import *
from topics.characters import *
from topics.functions import *
from topics.number_line import *
from topics.numerals import *
from scene import Scene
from camera import Camera
from mobject.svg_mobject import *
from mobject.tex_mobject import *
from mobject.vectorized_mobject import *
from eola.matrix import *
from eola.two_d_space import *
class OpeningQuote(Scene):
def construct(self):
words = TextMobject(
"``Last time, I asked: `What does",
"mathematics",
""" mean to you?', and some people answered: `The
manipulation of numbers, the manipulation of structures.'
And if I had asked what""",
"music",
"""means to you, would you have answered: `The
manipulation of notes?' '' """,
enforce_new_line_structure = False
)
words.highlight_by_tex("mathematics", BLUE)
words.highlight_by_tex("music", BLUE)
words.scale_to_fit_width(2*SPACE_WIDTH - 2)
words.to_edge(UP)
author = TextMobject("-Serge Lang")
author.highlight(YELLOW)
author.next_to(words, DOWN, buff = 0.5)
self.play(Write(words, run_time = 8))
self.dither(2)
self.play(Write(author, run_time = 3))
self.dither(2)
class NewSceneName(Scene):
def construct(self):
pass

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,6 @@ __all__ = [
"tex_mobject",
]
from mobject import Mobject
from mobject import Mobject, Group
from point_cloud_mobject import Point, Mobject1D, Mobject2D, PMobject
from vectorized_mobject import VMobject
from vectorized_mobject import VMobject, VGroup

View File

@ -612,7 +612,7 @@ class Mobject(object):
self.interpolate_color(mobject1, mobject2, alpha)
def interpolate_color(self, mobject1, mobject2, alpha):
raise Exception("Not implemented")
pass #To implement in subclass
def become_partial(self, mobject, a, b):
"""
@ -621,11 +621,12 @@ class Mobject(object):
Inputs 0 <= a < b <= 1 determine what portion
of mobject to become.
"""
pass #To implement in subclasses
#TODO, color?
def pointwise_become_partial(self, mobject, a, b):
raise Exception("Not implemented")
pass #To implement in subclass

View File

@ -416,6 +416,12 @@ class TeacherStudentsScene(Scene):
)
def student_says(self, *content, **kwargs):
if "pi_creature_target_mode" not in kwargs:
target_mode = random.choice([
"raise_right_hand",
"raise_left_hand",
])
kwargs["pi_creature_target_mode"] = target_mode
student = self.get_students()[kwargs.get("student_index", 1)]
return self.introduce_bubble(content, "speech", student, **kwargs)