3b1b-manim/old_projects/moser_main.py

1695 lines
60 KiB
Python
Raw Normal View History

2015-04-14 17:55:25 -07:00
#!/usr/bin/env python
import numpy as np
import itertools as it
import operator as op
from copy import deepcopy
from random import random, randint
import sys
2015-05-07 21:28:02 -07:00
import inspect
2015-04-14 17:55:25 -07:00
2019-05-02 20:36:14 -07:00
from manimlib.imports import *
2015-05-07 21:28:02 -07:00
from script_wrapper import command_line_create_scene
from functools import reduce
2015-04-14 17:55:25 -07:00
RADIUS = FRAME_Y_RADIUS - 0.1
2015-06-13 19:00:23 -07:00
CIRCLE_DENSITY = DEFAULT_POINT_DENSITY_1D*RADIUS
MOVIE_PREFIX = "moser/"
RADIANS = np.arange(0, 6, 6.0/7)
MORE_RADIANS = np.append(RADIANS, RADIANS + 0.5)
N_PASCAL_ROWS = 7
BIG_N_PASCAL_ROWS = 11
def int_list_to_string(int_list):
return "-".join(map(str, int_list))
def moser_function(n):
return choose(n, 4) + choose(n, 2) + 1
###########################################
class CircleScene(Scene):
args_list = [
(RADIANS[:x],)
for x in range(1, len(RADIANS)+1)
]
@staticmethod
def args_to_string(*args):
return str(len(args[0])) #Length of radians
def __init__(self, radians, radius = RADIUS, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
self.radius = radius
self.circle = Circle(density = CIRCLE_DENSITY).scale(self.radius)
self.points = [
(self.radius * np.cos(angle), self.radius * np.sin(angle), 0)
for angle in radians
]
self.dots = [Dot(point) for point in self.points]
self.lines = [Line(p1, p2) for p1, p2 in it.combinations(self.points, 2)]
self.n_equals = TexMobject(
2015-06-13 19:00:23 -07:00
"n=%d"%len(radians),
).shift((-FRAME_X_RADIUS+1, FRAME_Y_RADIUS-1.5, 0))
2015-06-13 19:00:23 -07:00
self.add(self.circle, self.n_equals, *self.dots + self.lines)
def generate_intersection_dots(self):
"""
Generates and adds attributes intersection_points and
intersection_dots, but does not yet add them to the scene
"""
self.intersection_points = [
intersection((p[0], p[2]), (p[1], p[3]))
for p in it.combinations(self.points, 4)
]
self.intersection_dots = [
Dot(point) for point in self.intersection_points
]
def chop_lines_at_intersection_points(self):
if not hasattr(self, "intersection_dots"):
self.generate_intersection_dots()
self.remove(*self.lines)
self.lines = []
for point_pair in it.combinations(self.points, 2):
2018-08-09 17:56:05 -07:00
int_points = [p for p in self.intersection_points if is_on_line(p, *point_pair)]
2015-06-13 19:00:23 -07:00
points = list(point_pair) + int_points
2018-08-09 17:56:05 -07:00
points = [(p[0], p[1], 0) for p in points]
2015-06-13 19:00:23 -07:00
points.sort(cmp = lambda x,y: cmp(x[0], y[0]))
self.lines += [
Line(points[i], points[i+1])
for i in range(len(points)-1)
]
self.add(*self.lines)
def chop_circle_at_points(self):
self.remove(self.circle)
self.circle_pieces = []
self.smaller_circle_pieces = []
for i in range(len(self.points)):
pp = self.points[i], self.points[(i+1)%len(self.points)]
transform = np.array([
[pp[0][0], pp[1][0], 0],
[pp[0][1], pp[1][1], 0],
[0, 0, 1]
])
circle = deepcopy(self.circle)
smaller_circle = deepcopy(self.circle)
for c in circle, smaller_circle:
c.points = np.dot(
c.points,
np.transpose(np.linalg.inv(transform))
)
c.filter_out(
lambda p : p[0] < 0 or p[1] < 0
)
if c == smaller_circle:
c.filter_out(
lambda p : p[0] > 4*p[1] or p[1] > 4*p[0]
)
c.points = np.dot(
c.points,
np.transpose(transform)
)
self.circle_pieces.append(circle)
self.smaller_circle_pieces.append(smaller_circle)
self.add(*self.circle_pieces)
def generate_regions(self):
self.regions = plane_partition_from_points(*self.points)
interior = Region(lambda x, y : x**2 + y**2 < self.radius**2)
2018-08-09 17:56:05 -07:00
list(map(lambda r : r.intersect(interior), self.regions))
2015-06-13 19:00:23 -07:00
self.exterior = interior.complement()
2015-04-14 17:55:25 -07:00
2015-05-17 15:08:51 -07:00
class CountSections(CircleScene):
def __init__(self, *args, **kwargs):
CircleScene.__init__(self, *args, **kwargs)
self.remove(*self.lines)
self.play(*[
2015-05-17 15:08:51 -07:00
Transform(Dot(points[i]),Line(points[i], points[1-i]))
for points in it.combinations(self.points, 2)
for i in (0, 1)
], run_time = 2.0)
regions = plane_partition_from_points(*self.points)
interior = Region(lambda x, y : x**2 + y**2 < self.radius**2)
2018-08-09 17:56:05 -07:00
list(map(lambda r : r.intersect(interior), regions))
regions = [r for r in regions if r.bool_grid.any()]
2015-05-17 15:08:51 -07:00
self.count_regions(regions, num_offset = ORIGIN)
class MoserPattern(CircleScene):
args_list = [(MORE_RADIANS,)]
def __init__(self, radians, *args, **kwargs):
CircleScene.__init__(self, radians, *args, **kwargs)
self.remove(*self.dots + self.lines + [self.n_equals])
n_equals, num = TexMobject(["n=", "10"]).split()
2015-05-17 15:08:51 -07:00
for mob in n_equals, num:
mob.shift((-FRAME_X_RADIUS + 1.5, FRAME_Y_RADIUS - 1.5, 0))
2015-05-17 15:08:51 -07:00
self.add(n_equals)
for n in range(1, len(radians)+1):
self.add(*self.dots[:n])
self.add(*[Line(p[0], p[1]) for p in it.combinations(self.points[:n], 2)])
tex_stuffs = [
TexMobject(str(moser_function(n))),
TexMobject(str(n)).shift(num.get_center())
2015-05-17 15:08:51 -07:00
]
self.add(*tex_stuffs)
2018-01-15 19:15:05 -08:00
self.wait(0.5)
2015-05-17 15:08:51 -07:00
self.remove(*tex_stuffs)
def hpsq_taylored_alpha(t):
return 0.3*np.sin(5*t-5)*np.exp(-20*(t-0.6)**2) + smooth(t)
2015-05-17 15:08:51 -07:00
class HardProblemsSimplerQuestions(Scene):
def __init__(self, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
right_center = np.array((4, 1, 0))
left_center = np.array((-5, 1, 0))
scale_factor = 0.7
fermat = dict([
(
sym,
Mobject(*TexMobjects(
2015-05-17 15:08:51 -07:00
["x","^"+sym,"+","y","^"+sym,"=","z","^"+sym]
))
)
for sym in ["n", "2", "3"]
])
# not_that_hard = TextMobject("(maybe not that hard...)").scale(0.5)
fermat2, fermat2_jargon = TexMobject([
2015-05-17 15:08:51 -07:00
r"&x^2 + y^2 = z^2 \\",
r"""
&(3, 4, 5) \\
&(5, 12, 13) \\
&(15, 8, 17) \\
&\quad \vdots \\
(m^2 - &n^2, 2mn, m^2 + n^2) \\
&\quad \vdots
"""
2015-06-27 04:49:10 -07:00
]).split()
fermat3, fermat3_jargon = TexMobject([
2015-05-17 15:08:51 -07:00
r"&x^3 + y^3 = z^3\\",
r"""
&y^3 = (z - x)(z - \omega x)(z - \omega^2 x) \\
&\mathds{Z}[\omega] \text{ is a UFD...}
"""
2015-06-27 04:49:10 -07:00
]).split()
2015-05-17 15:08:51 -07:00
for mob in [fermat2, fermat3, fermat["2"], fermat["3"],
fermat2_jargon, fermat3_jargon]:
mob.scale(scale_factor)
fermat["2"].shift(right_center)
fermat["3"].shift(left_center)
fermat["n"].shift((0, FRAME_Y_RADIUS - 1, 0))
2015-05-17 15:08:51 -07:00
shift_val = right_center - fermat2.get_center()
fermat2.shift(shift_val)
fermat2_jargon.shift(shift_val)
shift_val = left_center - fermat3.get_center()
fermat3.shift(shift_val)
fermat3_jargon.shift(shift_val)
copies = [
deepcopy(fermat["n"]).center().scale(scale_factor).shift(c)
for c in [left_center, right_center]
]
self.add(fermat["n"])
self.play(*[
2015-05-17 15:08:51 -07:00
Transform(deepcopy(fermat["n"]), f_copy)
for f_copy in copies
])
self.remove(*self.mobjects)
self.add(fermat["n"])
self.play(*[
CounterclockwiseTransform(mobs[0], mobs[1])
2015-05-17 15:08:51 -07:00
for f_copy, sym in zip(copies, ["3", "2"])
for mobs in zip(f_copy.split(), fermat[sym].split())
])
self.remove(*self.mobjects)
self.add(fermat["n"], fermat2, fermat3)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
circle_grid = Mobject(
2015-05-17 15:08:51 -07:00
Circle(),
Grid(radius = 2),
TexMobject(r"\mathds{R}^2").shift((2, -2, 0))
2015-05-17 15:08:51 -07:00
)
start_line = Line((-1, 0, 0), (-1, 2, 0))
end_line = Line((-1, 0, 0), (-1, -2, 0))
for mob in circle_grid, start_line, end_line:
mob.scale(0.5).shift(right_center + (0, 2, 0))
other_grid = Mobject(
2015-05-17 15:08:51 -07:00
Grid(radius = 2),
TexMobject(r"\mathds{C}").shift((2, -2, 0))
2015-05-17 15:08:51 -07:00
)
omega = np.array((0.5, 0.5*np.sqrt(3), 0))
dots = Mobject(*[
2015-05-17 15:08:51 -07:00
Dot(t*np.array((1, 0, 0)) + s * omega)
2018-08-09 17:56:05 -07:00
for t, s in it.product(list(range(-2, 3)), list(range(-2, 3)))
2015-05-17 15:08:51 -07:00
])
for mob in dots, other_grid:
mob.scale(0.5).shift(left_center + (0, 2, 0))
self.add(circle_grid, other_grid)
self.play(
2015-05-17 15:08:51 -07:00
FadeIn(fermat2_jargon),
FadeIn(fermat3_jargon),
CounterclockwiseTransform(start_line, end_line),
2015-05-17 15:08:51 -07:00
ShowCreation(dots)
)
2018-01-15 19:15:05 -08:00
self.wait()
all_mobjects = Mobject(*self.mobjects)
2015-05-17 15:08:51 -07:00
self.remove(*self.mobjects)
self.play(
2015-05-17 15:08:51 -07:00
Transform(
all_mobjects,
Point((FRAME_X_RADIUS, 0, 0))
2015-05-17 15:08:51 -07:00
),
Transform(
Point((-FRAME_X_RADIUS, 0, 0)),
Mobject(*CircleScene(RADIANS).mobjects)
2015-05-17 15:08:51 -07:00
)
)
2015-05-07 21:28:02 -07:00
class CountLines(CircleScene):
def __init__(self, radians, *args, **kwargs):
CircleScene.__init__(self, radians, *args, **kwargs)
#TODO, Count things explicitly?
text_center = (self.radius + 1, self.radius -1, 0)
scale_factor = 0.4
text = TexMobject(r"\text{How Many Lines?}", size = r"\large")
2015-05-07 21:28:02 -07:00
n = len(radians)
formula, answer = TexMobject([
2015-05-07 21:28:02 -07:00
r"{%d \choose 2} = \frac{%d(%d - 1)}{2} = "%(n, n, n),
str(choose(n, 2))
])
text.scale(scale_factor).shift(text_center)
x = text_center[0]
new_lines = [
Line((x-1, y, 0), (x+1, y, 0))
for y in np.arange(
-(self.radius - 1),
self.radius - 1,
(2*self.radius - 2)/len(self.lines)
)
2015-04-14 17:55:25 -07:00
]
2015-05-07 21:28:02 -07:00
self.add(text)
2018-01-15 19:15:05 -08:00
self.wait()
self.play(*[
2015-05-07 21:28:02 -07:00
Transform(line1, line2, run_time = 2)
for line1, line2 in zip(self.lines, new_lines)
])
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(text)
self.count(new_lines)
anims = [FadeIn(formula)]
for mob in self.mobjects:
2015-05-17 15:08:51 -07:00
if mob == self.number:
2015-05-07 21:28:02 -07:00
anims.append(Transform(mob, answer))
else:
anims.append(FadeOut(mob))
self.play(*anims, run_time = 1)
2015-05-07 21:28:02 -07:00
class CountIntersectionPoints(CircleScene):
def __init__(self, radians, *args, **kwargs):
radians = [r % (2*np.pi) for r in radians]
radians.sort()
CircleScene.__init__(self, radians, *args, **kwargs)
intersection_points = [
intersection((p[0], p[2]), (p[1], p[3]))
for p in it.combinations(self.points, 4)
]
2015-05-07 21:28:02 -07:00
intersection_dots = [Dot(point) for point in intersection_points]
text_center = (self.radius + 0.5, self.radius -0.5, 0)
size = r"\large"
scale_factor = 0.4
text = TexMobject(r"\text{How Many Intersection Points?}", size = size)
2015-05-07 21:28:02 -07:00
n = len(radians)
formula, answer = TexMobject([
2015-05-07 21:28:02 -07:00
r"{%d \choose 4} = \frac{%d(%d - 1)(%d - 2)(%d-3)}{1\cdot 2\cdot 3 \cdot 4}="%(n, n, n, n, n),
str(choose(n, 4))
2015-06-27 04:49:10 -07:00
]).split()
2015-05-07 21:28:02 -07:00
text.scale(scale_factor).shift(text_center)
self.add(text)
2015-05-17 15:08:51 -07:00
self.count(intersection_dots, mode="show", num_offset = ORIGIN)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
anims = []
for mob in self.mobjects:
2015-05-17 15:08:51 -07:00
if mob == self.number: #put in during count
2015-05-07 21:28:02 -07:00
anims.append(Transform(mob, answer))
else:
anims.append(FadeOut(mob))
anims.append(Animation(formula))
self.play(*anims, run_time = 1)
2015-05-07 21:28:02 -07:00
class NonGeneralPosition(CircleScene):
args_list = []
@staticmethod
def args_to_string(*args):
return ""
def __init__(self, *args, **kwargs):
radians = np.arange(1, 7)
new_radians = (np.pi/3)*radians
CircleScene.__init__(self, radians, *args, **kwargs)
new_cs = CircleScene(new_radians)
center_region = reduce(
Region.intersect,
[
HalfPlane((self.points[x], self.points[(x+3)%6]))
for x in [0, 4, 2]#Ya know, trust it
]
)
center_region
text = TexMobject(r"\text{This region disappears}", size = r"\large")
2015-05-07 21:28:02 -07:00
text.center().scale(0.5).shift((-self.radius, self.radius-0.3, 0))
arrow = Arrow(
point = (-0.35, -0.1, 0),
direction = (1, -1, 0),
length = self.radius + 1,
color = "white",
)
2018-03-30 11:51:31 -07:00
self.set_color_region(center_region, "green")
2015-05-07 21:28:02 -07:00
self.add(text, arrow)
2018-01-15 19:15:05 -08:00
self.wait(2)
2015-05-07 21:28:02 -07:00
self.remove(text, arrow)
self.reset_background()
self.play(*[
2015-05-07 21:28:02 -07:00
Transform(mob1, mob2, run_time = DEFAULT_ANIMATION_RUN_TIME)
for mob1, mob2 in zip(self.mobjects, new_self.mobjects)
])
2015-05-24 09:42:28 -07:00
class GeneralPositionRule(Scene):
def __init__(self, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
tuples = [
(
np.arange(0, 2*np.pi, np.pi/3),
"Not okay",
2018-08-09 17:56:05 -07:00
list(zip(list(range(3)), list(range(3, 6))))
2015-05-24 09:42:28 -07:00
),
(
RADIANS,
"Okay",
[],
),
(
np.arange(0, 2*np.pi, np.pi/4),
"Not okay",
2018-08-09 17:56:05 -07:00
list(zip(list(range(4)), list(range(4, 8))))
2015-05-24 09:42:28 -07:00
),
(
[2*np.pi*random() for x in range(5)],
"Okay",
[],
),
]
first_time = True
for radians, words, pairs in tuples:
cs = CircleScene(radians)
self.add(*cs.mobjects)
words_mob = TextMobject(words).scale(2).shift((5, 3, 0))
2015-05-24 09:42:28 -07:00
if not first_time:
self.add(words_mob)
if words == "Okay":
2018-03-30 11:51:31 -07:00
words_mob.set_color("green")
2018-01-15 19:15:05 -08:00
self.wait(2)
2015-05-24 09:42:28 -07:00
else:
2018-03-30 11:51:31 -07:00
words_mob.set_color()
2015-05-24 09:42:28 -07:00
intersecting_lines = [
2018-03-30 11:51:31 -07:00
line.scale_in_place(0.3).set_color()
2015-05-24 09:42:28 -07:00
for i, j in pairs
for line in [Line(cs.points[i], cs.points[j])]
]
self.play(*[
2015-05-24 09:42:28 -07:00
ShowCreation(line, run_time = 1.0)
for line in intersecting_lines
])
if first_time:
self.play(Transform(
Mobject(*intersecting_lines),
2015-05-24 09:42:28 -07:00
words_mob
))
first_time = False
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-24 09:42:28 -07:00
self.remove(*self.mobjects)
2015-05-07 21:28:02 -07:00
class LineCorrespondsWithPair(CircleScene):
args_list = [
(RADIANS, 2, 5),
2015-05-17 15:08:51 -07:00
(RADIANS, 0, 4)
]
2015-05-07 21:28:02 -07:00
@staticmethod
def args_to_string(*args):
return int_list_to_string(args[1:])
def __init__(self, radians, dot0_index, dot1_index,
*args, **kwargs):
CircleScene.__init__(self, radians, *args, **kwargs)
#Remove from self.lines list, so they won't be faded out
radians = list(radians)
r1, r2 = radians[dot0_index], radians[dot1_index]
line_index = list(it.combinations(radians, 2)).index((r1, r2))
line, dot0, dot1 = self.lines[line_index], self.dots[dot0_index], self.dots[dot1_index]
self.lines.remove(line)
self.dots.remove(dot0)
self.dots.remove(dot1)
2018-01-15 19:15:05 -08:00
self.wait()
self.play(*[
2015-05-24 09:42:28 -07:00
ApplyMethod(mob.fade, 0.2)
2015-05-07 21:28:02 -07:00
for mob in self.lines + self.dots
])
self.play(*[
2015-05-17 15:08:51 -07:00
Transform(
dot, Dot(dot.get_center(), 3*dot.radius),
rate_func = there_and_back
2015-05-17 15:08:51 -07:00
)
for dot in (dot0, dot1)
2015-05-07 21:28:02 -07:00
])
self.play(Transform(line, dot0))
2015-05-07 21:28:02 -07:00
class IllustrateNChooseK(Scene):
args_list = [
2015-05-17 15:08:51 -07:00
(n, k)
for n in range(1, 10)
for k in range(n+1)
]
2015-05-07 21:28:02 -07:00
@staticmethod
def args_to_string(*args):
return int_list_to_string(args)
def __init__(self, n, k, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
2018-08-09 17:56:05 -07:00
nrange = list(range(1, n+1))
2015-05-07 21:28:02 -07:00
tuples = list(it.combinations(nrange, k))
nrange_mobs = TexMobject([str(n) + r'\;' for n in nrange]).split()
tuple_mobs = TexMobjects(
2015-05-07 21:28:02 -07:00
[
(r'\\&' if c%(20//k) == 0 else r'\;\;') + str(p)
for p, c in zip(tuples, it.count())
2015-05-24 09:42:28 -07:00
],
size = r"\small",
)#TODO, scale these up!
2015-05-07 21:28:02 -07:00
tuple_terms = {
2 : "pairs",
3 : "triplets",
4 : "quadruplets",
}
tuple_term = tuple_terms[k] if k in tuple_terms else "tuples"
2015-05-17 15:08:51 -07:00
if k == 2:
str1 = r"{%d \choose %d} = \frac{%d(%d - 1)}{2}="%(n, k, n, n)
elif k == 4:
str1 = r"""
{%d \choose %d} =
\frac{%d(%d - 1)(%d-2)(%d-3)}{1\cdot 2\cdot 3 \cdot 4}=
"""%(n, k, n, n, n, n)
else:
str1 = r"{%d \choose %d} ="%(n, k)
form1, count, form2 = TexMobject([
2015-05-17 15:08:51 -07:00
str1,
2015-05-07 21:28:02 -07:00
"%d"%choose(n, k),
r" \text{ total %s}"%tuple_term
])
pronunciation = TextMobject(
2015-05-24 09:42:28 -07:00
"(pronounced ``%d choose %d\'\')"%(n, k)
)
2015-05-07 21:28:02 -07:00
for mob in nrange_mobs:
mob.shift((0, 2, 0))
for mob in form1, count, form2:
mob.scale(0.75).shift((0, -FRAME_Y_RADIUS + 1, 0))
2015-05-07 21:28:02 -07:00
count_center = count.get_center()
for mob in tuple_mobs:
mob.scale(0.6)
2015-05-24 09:42:28 -07:00
pronunciation.shift(
form1.get_center() + (0, 1, 0)
)
2015-05-07 21:28:02 -07:00
self.add(*nrange_mobs)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
run_time = 6.0
frame_time = run_time / len(tuples)
for tup, count in zip(tuples, it.count()):
count_mob = TexMobject(str(count+1))
2015-05-07 21:28:02 -07:00
count_mob.center().shift(count_center)
self.add(count_mob)
tuple_copy = Mobject(*[nrange_mobs[index-1] for index in tup])
2018-03-30 11:51:31 -07:00
tuple_copy.set_color()
2015-05-07 21:28:02 -07:00
self.add(tuple_copy)
self.add(tuple_mobs[count])
2018-01-15 19:15:05 -08:00
self.wait(frame_time)
2015-05-07 21:28:02 -07:00
self.remove(count_mob)
self.remove(tuple_copy)
self.add(count_mob)
self.play(FadeIn(Mobject(form1, form2, pronunciation)))
2015-05-07 21:28:02 -07:00
class IntersectionPointCorrespondances(CircleScene):
args_list = [
2018-08-09 17:56:05 -07:00
(RADIANS, list(range(0, 7, 2))),
2015-04-30 15:26:56 -07:00
]
2015-05-07 21:28:02 -07:00
@staticmethod
def args_to_string(*args):
return int_list_to_string(args[1])
def __init__(self, radians, indices, *args, **kwargs):
assert(len(indices) == 4)
indices.sort()
CircleScene.__init__(self, radians, *args, **kwargs)
intersection_point = intersection(
(self.points[indices[0]], self.points[indices[2]]),
(self.points[indices[1]], self.points[indices[3]])
)
if len(intersection_point) == 2:
intersection_point = list(intersection_point) + [0]
intersection_dot = Dot(intersection_point)
intersection_dot_arrow = Arrow(intersection_point).nudge()
self.add(intersection_dot)
2018-08-09 17:56:05 -07:00
pairs = list(it.combinations(list(range(len(radians))), 2))
2015-05-07 21:28:02 -07:00
lines_to_save = [
self.lines[pairs.index((indices[p0], indices[p1]))]
for p0, p1 in [(0, 2), (1, 3)]
]
dots_to_save = [
self.dots[p]
for p in indices
]
line_statement = TexMobject(r"\text{Pair of Lines}")
dots_statement = TexMobject(r"&\text{Quadruplet of} \\ &\text{outer dots}")
2015-05-07 21:28:02 -07:00
for mob in line_statement, dots_statement:
mob.center()
mob.scale(0.7)
mob.shift((FRAME_X_RADIUS-2, FRAME_Y_RADIUS - 1, 0))
2015-05-07 21:28:02 -07:00
fade_outs = []
line_highlights = []
dot_highlights = []
dot_pointers = []
for mob in self.mobjects:
if mob in lines_to_save:
line_highlights.append(Highlight(mob))
elif mob in dots_to_save:
dot_highlights.append(Highlight(mob))
dot_pointers.append(Arrow(mob.get_center()).nudge())
elif mob != intersection_dot:
fade_outs.append(FadeOut(mob, rate_func = not_quite_there))
2015-05-07 21:28:02 -07:00
self.add(intersection_dot_arrow)
self.play(Highlight(intersection_dot))
2015-05-07 21:28:02 -07:00
self.remove(intersection_dot_arrow)
self.play(*fade_outs)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.add(line_statement)
self.play(*line_highlights)
2015-05-07 21:28:02 -07:00
self.remove(line_statement)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.add(dots_statement, *dot_pointers)
self.play(*dot_highlights)
2015-05-07 21:28:02 -07:00
self.remove(dots_statement, *dot_pointers)
class LinesIntersectOutside(CircleScene):
args_list = [
(RADIANS, [2, 4, 5, 6]),
]
2015-05-07 21:28:02 -07:00
@staticmethod
def args_to_string(*args):
return int_list_to_string(args[1])
def __init__(self, radians, indices, *args, **kwargs):
assert(len(indices) == 4)
indices.sort()
CircleScene.__init__(self, radians, *args, **kwargs)
intersection_point = intersection(
(self.points[indices[0]], self.points[indices[1]]),
(self.points[indices[2]], self.points[indices[3]])
)
intersection_point = tuple(list(intersection_point) + [0])
intersection_dot = Dot(intersection_point)
2018-08-09 17:56:05 -07:00
pairs = list(it.combinations(list(range(len(radians))), 2))
2015-05-07 21:28:02 -07:00
lines_to_save = [
self.lines[pairs.index((indices[p0], indices[p1]))]
for p0, p1 in [(0, 1), (2, 3)]
]
self.play(*[
FadeOut(mob, rate_func = not_quite_there)
2015-05-07 21:28:02 -07:00
for mob in self.mobjects if mob not in lines_to_save
])
self.play(*[
2015-05-07 21:28:02 -07:00
Transform(
Line(self.points[indices[p0]], self.points[indices[p1]]),
Line(self.points[indices[p0]], intersection_point))
for p0, p1 in [(0, 1), (3, 2)]
] + [ShowCreation(intersection_dot)])
class QuadrupletsToIntersections(CircleScene):
def __init__(self, radians, *args, **kwargs):
CircleScene.__init__(self, radians, *args, **kwargs)
2018-08-09 17:56:05 -07:00
quadruplets = it.combinations(list(range(len(radians))), 4)
2015-05-07 21:28:02 -07:00
frame_time = 1.0
for quad in quadruplets:
intersection_dot = Dot(intersection(
(self.points[quad[0]], self.points[quad[2]]),
(self.points[quad[1]], self.points[quad[3]])
)).repeat(3)
dot_quad = [deepcopy(self.dots[i]) for i in quad]
for dot in dot_quad:
dot.scale_in_place(2)
dot_quad = Mobject(*dot_quad)
2018-03-30 11:51:31 -07:00
dot_quad.set_color()
2015-05-07 21:28:02 -07:00
self.add(dot_quad)
2018-01-15 19:15:05 -08:00
self.wait(frame_time / 3)
self.play(Transform(
2015-05-07 21:28:02 -07:00
dot_quad,
intersection_dot,
run_time = 3*frame_time/2
))
2015-05-17 15:08:51 -07:00
class GraphsAndEulersFormulaJoke(Scene):
def __init__(self, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
axes = Mobject(
2015-05-17 15:08:51 -07:00
NumberLine(),
NumberLine().rotate(np.pi / 2)
)
graph = ParametricFunction(
lambda t : (10*t, ((10*t)**3 - 10*t), 0),
expected_measure = 40.0
)
graph.filter_out(lambda x_y_z : abs(x_y_z[1]) > FRAME_Y_RADIUS)
2015-05-17 15:08:51 -07:00
self.add(axes)
self.play(ShowCreation(graph), run_time = 1.0)
eulers = TexMobject("e^{\pi i} = -1").shift((0, 3, 0))
self.play(CounterclockwiseTransform(
2015-05-17 15:08:51 -07:00
deepcopy(graph), eulers
))
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
self.remove(*self.mobjects)
self.add(eulers)
self.play(CounterclockwiseTransform(
Mobject(axes, graph),
Point((-FRAME_X_RADIUS, FRAME_Y_RADIUS, 0))
2015-05-17 15:08:51 -07:00
))
self.play(CounterclockwiseTransform(
2015-05-17 15:08:51 -07:00
eulers,
Point((FRAME_X_RADIUS, FRAME_Y_RADIUS, 0))
2015-05-17 15:08:51 -07:00
))
2015-05-07 21:28:02 -07:00
class DefiningGraph(GraphScene):
def __init__(self, *args, **kwargs):
GraphScene.__init__(self, *args, **kwargs)
2015-05-17 15:08:51 -07:00
word_center = (0, 3, 0)
vertices_word = TextMobject("``Vertices\"").shift(word_center)
edges_word = TextMobject("``Edges\"").shift(word_center)
2015-05-07 21:28:02 -07:00
dots, lines = self.vertices, self.edges
self.remove(*dots + lines)
all_dots = Mobject(*dots)
self.play(ShowCreation(all_dots))
2015-05-07 21:28:02 -07:00
self.remove(all_dots)
self.add(*dots)
self.play(FadeIn(vertices_word))
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
self.remove(vertices_word)
self.play(*[
2015-05-07 21:28:02 -07:00
ShowCreation(line) for line in lines
])
self.play(FadeIn(edges_word))
2015-05-07 21:28:02 -07:00
#Move to new graph
2015-05-17 15:08:51 -07:00
# new_graph = deepcopy(self.graph)
2015-06-22 10:14:53 -07:00
# new_graph.vertices = [
2015-05-17 15:08:51 -07:00
# (v[0] + 3*random(), v[1] + 3*random(), 0)
2015-06-22 10:14:53 -07:00
# for v in new_graph.vertices
2015-05-17 15:08:51 -07:00
# ]
# new_graph_scene = GraphScene(new_graph)
# self.play(*[
2015-05-17 15:08:51 -07:00
# Transform(m[0], m[1])
# for m in zip(self.mobjects, new_graph_scene.mobjects)
# ], run_time = 7.0)
class IntersectCubeGraphEdges(GraphScene):
args_list = []
@staticmethod
def args_to_string(*args):
return ""
def __init__(self, *args, **kwargs):
2015-06-22 10:14:53 -07:00
GraphScene.__init__(self, CubeGraph(), *args, **kwargs)
2015-05-17 15:08:51 -07:00
self.remove(self.edges[0], self.edges[4])
self.play(*[
2015-05-17 15:08:51 -07:00
Transform(
Line(self.points[i], self.points[j]),
CurvedLine(self.points[i], self.points[j]),
)
for i, j in [(0, 1), (5, 4)]
])
2015-05-07 21:28:02 -07:00
class DoubledEdges(GraphScene):
def __init__(self, *args, **kwargs):
GraphScene.__init__(self, *args, **kwargs)
lines_to_double = self.edges[:9:3]
crazy_lines = [
(
line,
Line(line.end, line.start),
CurvedLine(line.start, line.end) ,
2015-05-17 15:08:51 -07:00
CurvedLine(line.end, line.start)
)
2015-05-07 21:28:02 -07:00
for line in lines_to_double
]
2015-05-07 21:28:02 -07:00
anims = []
outward_curved_lines = []
kwargs = {"run_time" : 3.0}
for straight, backwards, inward, outward in crazy_lines:
anims += [
Transform(straight, inward, **kwargs),
Transform(backwards, outward, **kwargs),
]
outward_curved_lines.append(outward)
self.play(*anims)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(*outward_curved_lines)
class EulersFormula(GraphScene):
def __init__(self, *args, **kwargs):
GraphScene.__init__(self, *args, **kwargs)
terms = "V - E + F =2".split(" ")
form = dict([
(key, mob)
for key, mob in zip(terms, TexMobjects(terms))
2015-05-07 21:28:02 -07:00
])
2018-08-09 17:56:05 -07:00
for mob in list(form.values()):
mob.shift((0, FRAME_Y_RADIUS-0.7, 0))
2018-08-09 17:56:05 -07:00
formula = Mobject(*[form[k] for k in list(form.keys()) if k != "=2"])
2015-05-07 21:28:02 -07:00
new_form = dict([
(key, deepcopy(mob).shift((0, -0.7, 0)))
2018-08-09 17:56:05 -07:00
for key, mob in zip(list(form.keys()), list(form.values()))
])
2015-05-07 21:28:02 -07:00
self.add(formula)
colored_dots = [
2018-03-30 11:51:31 -07:00
deepcopy(d).scale_in_place(1.5).set_color("red")
2015-05-07 21:28:02 -07:00
for d in self.dots
]
colored_edges = [
Mobject(
2015-06-13 19:00:23 -07:00
Line(midpoint, start),
Line(midpoint, end),
2018-03-30 11:51:31 -07:00
).set_color("red")
2015-05-07 21:28:02 -07:00
for e in self.edges
2015-06-13 19:00:23 -07:00
for start, end, midpoint in [
2015-06-22 10:14:53 -07:00
(e.start, e.end, (e.start + e.end)/2.0)
2015-06-13 19:00:23 -07:00
]
2015-05-07 21:28:02 -07:00
]
frame_time = 0.3
2015-05-07 21:28:02 -07:00
self.generate_regions()
parameters = [
2015-05-17 15:08:51 -07:00
(colored_dots, "V", "mobject", "-", "show"),
2015-06-22 10:14:53 -07:00
(colored_edges, "E", "mobject", "+", "show"),
2015-05-17 15:08:51 -07:00
(self.regions, "F", "region", "=2", "show_all")
2015-05-07 21:28:02 -07:00
]
for items, letter, item_type, symbol, mode in parameters:
self.count(
2015-05-17 15:08:51 -07:00
items,
2015-05-07 21:28:02 -07:00
item_type = item_type,
mode = mode,
num_offset = new_form[letter].get_center(),
run_time = frame_time*len(items)
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
if item_type == "mobject":
self.remove(*items)
self.add(new_form[symbol])
class CannotDirectlyApplyEulerToMoser(CircleScene):
def __init__(self, radians, *args, **kwargs):
CircleScene.__init__(self, radians, *args, **kwargs)
self.remove(self.n_equals)
n_equals, intersection_count = TexMobject([
2015-05-07 21:28:02 -07:00
r"&n = %d\\"%len(radians),
r"&{%d \choose 4} = %d"%(len(radians), choose(len(radians), 4))
2015-06-27 04:49:10 -07:00
]).split()
2015-05-07 21:28:02 -07:00
shift_val = self.n_equals.get_center() - n_equals.get_center()
for mob in n_equals, intersection_count:
mob.shift(shift_val)
self.add(n_equals)
2015-05-17 15:08:51 -07:00
yellow_dots = [
2018-03-30 11:51:31 -07:00
d.set_color("yellow").scale_in_place(2)
2015-05-17 15:08:51 -07:00
for d in deepcopy(self.dots)
]
yellow_lines = Mobject(*[
2018-03-30 11:51:31 -07:00
l.set_color("yellow") for l in deepcopy(self.lines)
2015-05-17 15:08:51 -07:00
])
self.play(*[
2015-05-07 21:28:02 -07:00
ShowCreation(dot) for dot in yellow_dots
], run_time = 1.0)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(*yellow_dots)
self.play(ShowCreation(yellow_lines))
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(yellow_lines)
cannot_intersect = TextMobject(r"""
2015-05-07 21:28:02 -07:00
Euler's formula does not apply to \\
graphs whose edges intersect!
"""
)
2015-05-07 21:28:02 -07:00
cannot_intersect.center()
for mob in self.mobjects:
mob.fade(0.3)
self.add(cannot_intersect)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(cannot_intersect)
for mob in self.mobjects:
mob.fade(1/0.3)
self.generate_intersection_dots()
self.play(FadeIn(intersection_count), *[
2015-05-07 21:28:02 -07:00
ShowCreation(dot) for dot in self.intersection_dots
])
class ShowMoserGraphLines(CircleScene):
def __init__(self, radians, *args, **kwargs):
2018-08-09 17:56:05 -07:00
radians = list(set([x%(2*np.pi) for x in radians]))
2015-05-07 21:28:02 -07:00
radians.sort()
CircleScene.__init__(self, radians, *args, **kwargs)
n, plus_n_choose_4 = TexMobject(["n", "+{n \\choose 4}"]).split()
n_choose_2, plus_2_n_choose_4, plus_n = TexMobject([
2015-05-17 15:08:51 -07:00
r"{n \choose 2}",r"&+2{n \choose 4}\\",r"&+n"
2015-06-27 04:49:10 -07:00
]).split()
2015-05-17 15:08:51 -07:00
for mob in n, plus_n_choose_4, n_choose_2, plus_2_n_choose_4, plus_n:
mob.shift((FRAME_X_RADIUS - 2, FRAME_Y_RADIUS-1, 0))
2015-05-07 21:28:02 -07:00
self.chop_lines_at_intersection_points()
self.add(*self.intersection_dots)
small_lines = [
deepcopy(line).scale_in_place(0.5)
for line in self.lines
]
2015-05-17 15:08:51 -07:00
for mobs, symbol in [
(self.dots, n),
(self.intersection_dots, plus_n_choose_4),
(self.lines, n_choose_2)
]:
self.add(symbol)
compound = Mobject(*mobs)
2015-05-17 15:08:51 -07:00
if mobs in (self.dots, self.intersection_dots):
self.remove(*mobs)
self.play(CounterclockwiseTransform(
2015-05-17 15:08:51 -07:00
compound,
deepcopy(compound).scale(1.05),
rate_func = there_and_back,
2015-05-17 15:08:51 -07:00
run_time = 2.0,
))
else:
2018-03-30 11:51:31 -07:00
compound.set_color("yellow")
self.play(ShowCreation(compound))
2015-05-17 15:08:51 -07:00
self.remove(compound)
if mobs == self.intersection_dots:
self.remove(n, plus_n_choose_4)
self.play(*[
2015-05-07 21:28:02 -07:00
Transform(line, small_line, run_time = 3.0)
for line, small_line in zip(self.lines, small_lines)
])
yellow_lines = Mobject(*[
2018-03-30 11:51:31 -07:00
line.set_color("yellow") for line in small_lines
2015-05-17 15:08:51 -07:00
])
self.add(plus_2_n_choose_4)
self.play(ShowCreation(yellow_lines))
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
self.remove(yellow_lines)
2015-05-07 21:28:02 -07:00
self.chop_circle_at_points()
self.play(*[
2015-05-07 21:28:02 -07:00
Transform(p, sp, run_time = 3.0)
for p, sp in zip(self.circle_pieces, self.smaller_circle_pieces)
])
2015-05-17 15:08:51 -07:00
self.add(plus_n)
self.play(ShowCreation(Mobject(*[
2018-03-30 11:51:31 -07:00
mob.set_color("yellow") for mob in self.circle_pieces
2015-05-17 15:08:51 -07:00
])))
class HowIntersectionChopsLine(CircleScene):
args_list = [
2018-08-09 17:56:05 -07:00
(RADIANS, list(range(0, 7, 2))),
2015-05-17 15:08:51 -07:00
]
@staticmethod
def args_to_string(*args):
return int_list_to_string(args[1])
def __init__(self, radians, indices, *args, **kwargs):
assert(len(indices) == 4)
indices.sort()
CircleScene.__init__(self, radians, *args, **kwargs)
intersection_point = intersection(
(self.points[indices[0]], self.points[indices[2]]),
(self.points[indices[1]], self.points[indices[3]])
)
if len(intersection_point) == 2:
intersection_point = list(intersection_point) + [0]
2018-08-09 17:56:05 -07:00
pairs = list(it.combinations(list(range(len(radians))), 2))
2015-05-17 15:08:51 -07:00
lines = [
Line(self.points[indices[p0]], self.points[indices[p1]])
for p0, p1 in [(2, 0), (1, 3)]
]
self.remove(*[
self.lines[pairs.index((indices[p0], indices[p1]))]
for p0, p1 in [(0, 2), (1, 3)]
])
self.add(*lines)
self.play(*[
2015-05-17 15:08:51 -07:00
FadeOut(mob)
for mob in self.mobjects
if mob not in lines
])
new_lines = [
Line(line.start, intersection_point)
for line in lines
] + [
Line(intersection_point, line.end)
for line in lines
]
self.play(*[
2015-05-17 15:08:51 -07:00
Transform(
line,
Line(
(-3, h, 0),
(3, h, 0)
),
rate_func = there_and_back,
2015-05-17 15:08:51 -07:00
run_time = 3.0
)
for line, h in zip(lines, (-1, 1))
])
self.remove(*lines)
self.play(*[
2015-05-17 15:08:51 -07:00
Transform(
line,
deepcopy(line).scale(1.1).scale_in_place(1/1.1),
run_time = 1.5
)
for line in new_lines
])
2015-05-07 21:28:02 -07:00
2015-05-24 09:42:28 -07:00
class ApplyEulerToMoser(CircleScene):
2015-05-07 21:28:02 -07:00
def __init__(self, *args, **kwargs):
2015-05-24 09:42:28 -07:00
radius = 2
CircleScene.__init__(self, *args, radius = radius, **kwargs)
self.generate_intersection_dots()
self.chop_lines_at_intersection_points()
self.chop_circle_at_points()
self.generate_regions()
for dot in self.dots + self.intersection_dots:
dot.scale_in_place(radius / RADIUS)
self.remove(*self.mobjects)
2015-05-17 15:08:51 -07:00
V = {}
minus = {}
minus1 = {}
E = {}
plus = {}
plus1 = {}
plus2 = {}
F = {}
equals = {}
two = {}
two1 = {}
n = {}
n1 = {}
nc2 = {}
nc4 = {}
nc41 = {}
dicts = [V, minus, minus1, E, plus, plus1, plus2, F,
equals, two, two1, n, n1, nc2, nc4, nc41]
V[1], minus[1], E[1], plus[1], F[1], equals[1], two[1] = \
TexMobject(["V", "-", "E", "+", "F", "=", "2"]).split()
2015-05-17 15:08:51 -07:00
F[2], equals[2], E[2], minus[2], V[2], plus[2], two[2] = \
TexMobject(["F", "=", "E", "-", "V", "+", "2"]).split()
2015-05-17 15:08:51 -07:00
F[3], equals[3], E[3], minus[3], n[3], minus1[3], nc4[3], plus[3], two[3] = \
TexMobject(["F", "=", "E", "-", "n", "-", r"{n \choose 4}", "+", "2"]).split()
2015-05-17 15:08:51 -07:00
F[4], equals[4], nc2[4], plus1[4], two1[4], nc41[4], plus2[4], n1[4], minus[4], n[4], minus1[4], nc4[4], plus[4], two[4] = \
TexMobject(["F", "=", r"{n \choose 2}", "+", "2", r"{n \choose 4}", "+", "n","-", "n", "-", r"{n \choose 4}", "+", "2"]).split()
2015-05-17 15:08:51 -07:00
F[5], equals[5], nc2[5], plus1[5], two1[5], nc41[5], minus1[5], nc4[5], plus[5], two[5] = \
TexMobject(["F", "=", r"{n \choose 2}", "+", "2", r"{n \choose 4}", "-", r"{n \choose 4}", "+", "2"]).split()
2015-05-17 15:08:51 -07:00
F[6], equals[6], nc2[6], plus1[6], nc4[6], plus[6], two[6] = \
TexMobject(["F", "=", r"{n \choose 2}", "+", r"{n \choose 4}", "+", "2"]).split()
2015-05-17 15:08:51 -07:00
F[7], equals[7], two[7], plus[7], nc2[7], plus1[7], nc4[7] = \
TexMobject(["F", "=", "2", "+", r"{n \choose 2}", "+", r"{n \choose 4}"]).split()
2015-05-24 09:42:28 -07:00
shift_val = (0, 3, 0)
2015-05-17 15:08:51 -07:00
for d in dicts:
if not d:
continue
2018-08-09 17:56:05 -07:00
main_key = list(d.keys())[0]
for key in list(d.keys()):
2015-05-24 09:42:28 -07:00
d[key].shift(shift_val)
2015-05-17 15:08:51 -07:00
main_center = d[main_key].get_center()
2018-08-09 17:56:05 -07:00
for key in list(d.keys()):
2015-05-17 15:08:51 -07:00
d[key] = deepcopy(d[main_key]).shift(
d[key].get_center() - main_center
)
self.play(*[
CounterclockwiseTransform(d[1], d[2], run_time = 2.0)
2015-05-17 15:08:51 -07:00
for d in [V, minus, E, plus, F, equals, two]
2015-05-07 21:28:02 -07:00
])
2018-01-15 19:15:05 -08:00
self.wait()
2018-03-30 11:51:31 -07:00
F[1].set_color()
2015-05-24 09:42:28 -07:00
self.add(*self.lines + self.circle_pieces)
for region in self.regions:
2018-03-30 11:51:31 -07:00
self.set_color_region(region)
self.set_color_region(self.exterior, "blue")
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-24 09:42:28 -07:00
self.reset_background()
2018-03-30 11:51:31 -07:00
F[1].set_color("white")
E[1].set_color()
2015-05-24 09:42:28 -07:00
self.remove(*self.lines + self.circle_pieces)
self.play(*[
2015-05-24 09:42:28 -07:00
Transform(
deepcopy(line),
deepcopy(line).scale_in_place(0.5),
run_time = 2.0,
)
for line in self.lines
] + [
Transform(
deepcopy(cp), scp,
run_time = 2.0
)
for cp, scp in zip(self.circle_pieces, self.smaller_circle_pieces)
])
2018-01-15 19:15:05 -08:00
self.wait()
2018-03-30 11:51:31 -07:00
E[1].set_color("white")
V[1].set_color()
2015-05-24 09:42:28 -07:00
self.add(*self.dots + self.intersection_dots)
self.remove(*self.lines + self.circle_pieces)
self.play(*[
2015-05-24 09:42:28 -07:00
Transform(
deepcopy(dot),
2018-03-30 11:51:31 -07:00
deepcopy(dot).scale_in_place(1.4).set_color("yellow")
2015-05-24 09:42:28 -07:00
)
for dot in self.dots + self.intersection_dots
] + [
Transform(
deepcopy(line),
deepcopy(line).fade(0.4)
)
for line in self.lines + self.circle_pieces
])
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-24 09:42:28 -07:00
all_mobs = [mob for mob in self.mobjects]
self.remove(*all_mobs)
self.add(*[d[1] for d in [V, minus, E, plus, F, equals, two]])
2018-03-30 11:51:31 -07:00
V[1].set_color("white")
two[1].set_color()
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-24 09:42:28 -07:00
self.add(*all_mobs)
self.remove(*[d[1] for d in [V, minus, E, plus, F, equals, two]])
self.play(
Transform(V[2].repeat(2), Mobject(n[3], minus1[3], nc4[3])),
2015-05-17 15:08:51 -07:00
*[
Transform(d[2], d[3])
for d in [F, equals, E, minus, plus, two]
]
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(*self.mobjects)
self.play(
Transform(E[3], Mobject(
2015-05-17 15:08:51 -07:00
nc2[4], plus1[4], two1[4], nc41[4], plus2[4], n1[4]
)),
*[
Transform(d[3], d[4])
for d in [F, equals, minus, n, minus1, nc4, plus, two]
2015-05-24 09:42:28 -07:00
] + [
Transform(
deepcopy(line),
deepcopy(line).scale_in_place(0.5),
)
for line in self.lines
] + [
Transform(deepcopy(cp), scp)
for cp, scp in zip(self.circle_pieces, self.smaller_circle_pieces)
],
run_time = 2.0
2015-05-17 15:08:51 -07:00
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
self.remove(*self.mobjects)
self.play(
2015-05-17 15:08:51 -07:00
Transform(
Mobject(plus2[4], n1[4], minus[4], n[4]),
Point((FRAME_X_RADIUS, FRAME_Y_RADIUS, 0))
2015-05-17 15:08:51 -07:00
),
*[
Transform(d[4], d[5])
for d in [F, equals, nc2, plus1, two1,
nc41, minus1, nc4, plus, two]
]
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
self.remove(*self.mobjects)
self.play(
2015-05-17 15:08:51 -07:00
Transform(nc41[5], nc4[6]),
Transform(two1[5], Point(nc4[6].get_center())),
*[
Transform(d[5], d[6])
for d in [F, equals, nc2, plus1, nc4, plus, two]
]
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
self.remove(*self.mobjects)
self.play(
CounterclockwiseTransform(two[6], two[7]),
CounterclockwiseTransform(plus[6], plus[7]),
2015-05-17 15:08:51 -07:00
*[
Transform(d[6], d[7])
for d in [F, equals, nc2, plus1, nc4]
]
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-24 09:42:28 -07:00
self.add(*self.lines + self.circle_pieces)
for region in self.regions:
2018-03-30 11:51:31 -07:00
self.set_color_region(region)
2018-01-15 19:15:05 -08:00
self.wait()
2018-03-30 11:51:31 -07:00
self.set_color_region(self.exterior, "blue")
2018-01-15 19:15:05 -08:00
self.wait()
2018-03-30 11:51:31 -07:00
self.set_color_region(self.exterior, "black")
2015-05-17 15:08:51 -07:00
self.remove(two[6])
two = two[7]
one = TexMobject("1").shift(two.get_center())
2018-03-30 11:51:31 -07:00
two.set_color("red")
2015-05-17 15:08:51 -07:00
self.add(two)
self.play(CounterclockwiseTransform(two, one))
2015-05-17 15:08:51 -07:00
class FormulaRelatesToPowersOfTwo(Scene):
def __init__(self, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
pof2_range = [1, 2, 3, 4, 5, 10]
strings = [
[
r"&1 + {%d \choose 2} + {%d \choose 4} ="%(n, n),
r"1 + %d + %d ="%(choose(n, 2), choose(n, 4)),
r"%d \\"%moser_function(n)
]
for n in [1, 2, 3, 4, 5, 10]
]
everything = TexMobjects(sum(strings, []), size = r"\large")
2015-05-17 15:08:51 -07:00
scale_factor = 1
for mob in everything:
mob.scale(scale_factor)
Mobject(*everything).show()
2015-05-17 15:08:51 -07:00
forms = everything[0::3]
sums = everything[1::3]
results = everything[2::3]
self.add(*forms)
self.play(*[
2015-05-17 15:08:51 -07:00
FadeIn(s) for s in sums
2015-05-07 21:28:02 -07:00
])
2018-01-15 19:15:05 -08:00
self.wait()
self.play(*[
2015-05-17 15:08:51 -07:00
Transform(deepcopy(s), result)
for s, result in zip(sums, results)
])
powers_of_two = [
TexMobject("2^{%d}"%(i-1)
2015-05-17 15:08:51 -07:00
).scale(scale_factor
).shift(result.get_center()
2018-03-30 11:51:31 -07:00
).set_color()
2015-05-17 15:08:51 -07:00
for i, result in zip(pof2_range, results)
]
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-17 15:08:51 -07:00
self.remove(*self.mobjects)
self.add(*forms + sums + results)
self.play(*[
CounterclockwiseTransform(result, pof2)
2015-05-17 15:08:51 -07:00
for result, pof2 in zip(results, powers_of_two)
])
2015-05-07 21:28:02 -07:00
class DrawPascalsTriangle(PascalsTriangleScene):
def __init__(self, *args, **kwargs):
PascalsTriangleScene.__init__(self, *args, **kwargs)
self.remove(*self.mobjects)
self.add(self.coords_to_mobs[0][0])
for n in range(1, nrows):
starts = [deepcopy(self.coords_to_mobs[n-1][0])]
starts += [
Mobject(
2015-05-07 21:28:02 -07:00
self.coords_to_mobs[n-1][k-1],
self.coords_to_mobs[n-1][k]
)
for k in range(1, n)
]
starts.append(deepcopy(self.coords_to_mobs[n-1][n-1]))
self.play(*[
2015-05-07 21:28:02 -07:00
Transform(starts[i], self.coords_to_mobs[n][i],
run_time = 1.5, black_out_extra_points = False)
for i in range(n+1)
])
class PascalRuleExample(PascalsTriangleScene):
def __init__(self, nrows, *args, **kwargs):
assert(nrows > 1)
PascalsTriangleScene.__init__(self, nrows, *args, **kwargs)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
n = randint(2, nrows-1)
k = randint(1, n-1)
2018-03-30 11:51:31 -07:00
self.coords_to_mobs[n][k].set_color("green")
2018-01-15 19:15:05 -08:00
self.wait()
plus = TexMobject("+").scale(0.5)
2015-05-07 21:28:02 -07:00
nums_above = [self.coords_to_mobs[n-1][k-1], self.coords_to_mobs[n-1][k]]
plus.center().shift(sum(map(Mobject.get_center, nums_above)) / 2)
self.add(plus)
for mob in nums_above + [plus]:
2018-03-30 11:51:31 -07:00
mob.set_color("yellow")
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
class PascalsTriangleWithNChooseK(PascalsTriangleScene):
def __init__(self, *args, **kwargs):
PascalsTriangleScene.__init__(self, *args, **kwargs)
self.generate_n_choose_k_mobs()
mob_dicts = (self.coords_to_mobs, self.coords_to_n_choose_k)
for i in [0, 1]:
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(*self.mobjects)
self.play(*[
CounterclockwiseTransform(
2015-05-07 21:28:02 -07:00
deepcopy(mob_dicts[i][n][k]),
mob_dicts[1-i][n][k]
)
for n, k in self.coords
])
self.remove(*self.mobjects)
self.add(*[mob_dicts[1-i][n][k] for n, k in self.coords])
2015-05-12 14:51:21 -07:00
class PascalsTriangleNChooseKExample(PascalsTriangleScene):
args_list = [
(N_PASCAL_ROWS, 5, 3),
]
@staticmethod
def args_to_string(nrows, n, k):
return "%d_n=%d_k=%d"%(nrows, n, k)
def __init__(self, nrows, n, k, *args, **kwargs):
PascalsTriangleScene.__init__(self, nrows, *args, **kwargs)
2018-01-15 19:15:05 -08:00
wait_time = 0.5
2015-05-12 14:51:21 -07:00
triangle_terms = [self.coords_to_mobs[a][b] for a, b in self.coords]
formula_terms = left, n_mob, k_mob, right = TexMobject([
2015-05-12 14:51:21 -07:00
r"\left(", str(n), r"\atop %d"%k, r"\right)"
])
formula_center = (FRAME_X_RADIUS - 1, FRAME_Y_RADIUS - 1, 0)
2015-05-12 14:51:21 -07:00
self.remove(*triangle_terms)
self.add(*formula_terms)
2018-01-15 19:15:05 -08:00
self.wait()
self.play(*
2015-05-12 14:51:21 -07:00
[
ShowCreation(mob) for mob in triangle_terms
]+[
2015-05-24 09:42:28 -07:00
ApplyMethod(mob.shift, formula_center)
2015-05-12 14:51:21 -07:00
for mob in formula_terms
],
run_time = 1.0
)
self.remove(n_mob, k_mob)
for a in range(n+1):
row = [self.coords_to_mobs[a][b] for b in range(a+1)]
a_mob = TexMobject(str(a))
2015-05-12 14:51:21 -07:00
a_mob.shift(n_mob.get_center())
2018-03-30 11:51:31 -07:00
a_mob.set_color("green")
2015-05-12 14:51:21 -07:00
self.add(a_mob)
for mob in row:
2018-03-30 11:51:31 -07:00
mob.set_color("green")
2018-01-15 19:15:05 -08:00
self.wait(wait_time)
2015-05-12 14:51:21 -07:00
if a < n:
for mob in row:
2018-03-30 11:51:31 -07:00
mob.set_color("white")
2015-05-12 14:51:21 -07:00
self.remove(a_mob)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-12 14:51:21 -07:00
for b in range(k+1):
b_mob = TexMobject(str(b))
2015-05-12 14:51:21 -07:00
b_mob.shift(k_mob.get_center())
2018-03-30 11:51:31 -07:00
b_mob.set_color("yellow")
2015-05-12 14:51:21 -07:00
self.add(b_mob)
2018-03-30 11:51:31 -07:00
self.coords_to_mobs[n][b].set_color("yellow")
2018-01-15 19:15:05 -08:00
self.wait(wait_time)
2015-05-12 14:51:21 -07:00
if b < k:
2018-03-30 11:51:31 -07:00
self.coords_to_mobs[n][b].set_color("green")
2015-05-12 14:51:21 -07:00
self.remove(b_mob)
self.play(*[
2015-05-24 09:42:28 -07:00
ApplyMethod(mob.fade, 0.2)
2015-05-12 14:51:21 -07:00
for mob in triangle_terms
if mob != self.coords_to_mobs[n][k]
])
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-12 14:51:21 -07:00
2015-05-07 21:28:02 -07:00
class PascalsTriangleSumRows(PascalsTriangleScene):
def __init__(self, *args, **kwargs):
PascalsTriangleScene.__init__(self, *args, **kwargs)
pluses = []
powers_of_two = []
equalses = []
powers_of_two_symbols = []
plus = TexMobject("+")
2015-05-07 21:28:02 -07:00
desired_plus_width = self.coords_to_mobs[0][0].get_width()
if plus.get_width() > desired_plus_width:
plus.scale(desired_plus_width / plus.get_width())
for n, k in self.coords:
if k == 0:
continue
new_plus = deepcopy(plus)
new_plus.center().shift(self.coords_to_mobs[n][k].get_center())
new_plus.shift((-self.cell_width / 2.0, 0, 0))
pluses.append(new_plus)
equals = TexMobject("=")
2015-05-07 21:28:02 -07:00
equals.scale(min(1, 0.7 * self.cell_height / equals.get_width()))
for n in range(self.nrows):
new_equals = deepcopy(equals)
pof2 = TexMobjects(str(2**n))
symbol = TexMobject("2^{%d}"%n)
2015-05-07 21:28:02 -07:00
desired_center = np.array((
self.diagram_width / 2.0,
self.coords_to_mobs[n][0].get_center()[1],
0
))
new_equals.shift(desired_center - new_equals.get_center())
desired_center += (1.5*equals.get_width(), 0, 0)
scale_factor = self.coords_to_mobs[0][0].get_height() / pof2.get_height()
for mob in pof2, symbol:
mob.center().scale(scale_factor).shift(desired_center)
symbol.shift((0, 0.5*equals.get_height(), 0)) #FUAH! Stupid
powers_of_two.append(pof2)
equalses.append(new_equals)
powers_of_two_symbols.append(symbol)
self.play(FadeIn(Mobject(*pluses)))
2015-05-07 21:28:02 -07:00
run_time = 0.5
to_remove = []
for n in range(self.nrows):
start = Mobject(*[self.coords_to_mobs[n][k] for k in range(n+1)])
2015-05-07 21:28:02 -07:00
to_remove.append(start)
self.play(
2015-05-07 21:28:02 -07:00
Transform(start, powers_of_two[n]),
FadeIn(equalses[n]),
run_time = run_time
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-07 21:28:02 -07:00
self.remove(*to_remove)
self.add(*powers_of_two)
for n in range(self.nrows):
self.play(CounterclockwiseTransform(
2015-05-07 21:28:02 -07:00
powers_of_two[n], powers_of_two_symbols[n],
run_time = run_time
))
self.remove(powers_of_two[n])
self.add(powers_of_two_symbols[n])
2015-04-30 15:26:56 -07:00
2015-04-14 17:55:25 -07:00
2015-05-12 14:51:21 -07:00
class MoserSolutionInPascal(PascalsTriangleScene):
args_list = [
(N_PASCAL_ROWS, n)
for n in range(3, 8)
] + [
(BIG_N_PASCAL_ROWS, 10)
]
@staticmethod
def args_to_string(nrows, n):
return "%d_n=%d"%(nrows,n)
def __init__(self, nrows, n, *args, **kwargs):
PascalsTriangleScene.__init__(self, nrows, *args, **kwargs)
term_color = "green"
self.generate_n_choose_k_mobs()
self.remove(*[self.coords_to_mobs[n0][k0] for n0, k0 in self.coords])
terms = one, plus0, n_choose_2, plus1, n_choose_4 = TexMobject([
2015-05-12 14:51:21 -07:00
"1", "+", r"{%d \choose 2}"%n, "+", r"{%d \choose 4}"%n
2015-06-27 04:49:10 -07:00
]).split()
2015-05-12 14:51:21 -07:00
target_terms = []
for k in range(len(terms)):
if k%2 == 0 and k <= n:
new_term = deepcopy(self.coords_to_n_choose_k[n][k])
2018-03-30 11:51:31 -07:00
new_term.set_color(term_color)
2015-05-12 14:51:21 -07:00
else:
new_term = Point(
self.coords_to_center(n, k)
)
target_terms.append(new_term)
self.add(*terms)
2018-01-15 19:15:05 -08:00
self.wait()
self.play(*
2015-05-12 14:51:21 -07:00
[
FadeIn(self.coords_to_n_choose_k[n0][k0])
for n0, k0 in self.coords
if (n0, k0) not in [(n, 0), (n, 2), (n, 4)]
]+[
Transform(term, target_term)
for term, target_term in zip(terms, target_terms)
]
)
2018-01-15 19:15:05 -08:00
self.wait()
2018-08-09 17:56:05 -07:00
term_range = list(range(0, min(4, n)+1, 2))
2015-05-12 14:51:21 -07:00
target_terms = dict([
2018-03-30 11:51:31 -07:00
(k, deepcopy(self.coords_to_mobs[n][k]).set_color(term_color))
2015-05-12 14:51:21 -07:00
for k in term_range
])
self.play(*
2015-05-12 14:51:21 -07:00
[
CounterclockwiseTransform(
2015-05-12 14:51:21 -07:00
self.coords_to_n_choose_k[n0][k0],
self.coords_to_mobs[n0][k0]
)
for n0, k0 in self.coords
if (n0, k0) not in [(n, k) for k in term_range]
]+[
CounterclockwiseTransform(terms[k], target_terms[k])
2015-05-12 14:51:21 -07:00
for k in term_range
]
)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-12 14:51:21 -07:00
for k in term_range:
if k == 0:
above_terms = [self.coords_to_n_choose_k[n-1][k]]
elif k == n:
above_terms = [self.coords_to_n_choose_k[n-1][k-1]]
else:
above_terms = [
self.coords_to_n_choose_k[n-1][k-1],
self.coords_to_n_choose_k[n-1][k],
]
self.add(self.coords_to_mobs[n][k])
self.play(Transform(
2015-05-12 14:51:21 -07:00
terms[k],
2018-03-30 11:51:31 -07:00
Mobject(*above_terms).set_color(term_color)
2015-05-12 14:51:21 -07:00
))
self.remove(*above_terms)
2018-01-15 19:15:05 -08:00
self.wait()
terms_sum = TexMobject(str(moser_function(n)))
terms_sum.shift((FRAME_X_RADIUS-1, terms[0].get_center()[1], 0))
2018-03-30 11:51:31 -07:00
terms_sum.set_color(term_color)
self.play(Transform(Mobject(*terms), terms_sum))
2015-05-12 14:51:21 -07:00
2015-05-24 09:42:28 -07:00
class RotatingPolyhedra(Scene):
args_list = [
([Cube, Dodecahedron],)
]
@staticmethod
def args_to_string(class_list):
return "".join([c.__name__ for c in class_list])
def __init__(self, polyhedra_classes, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
rot_kwargs = {
"radians" : np.pi / 2,
"run_time" : 5.0,
"axis" : [0, 1, 0]
}
polyhedra = [
Class().scale(1.5).shift((1, 0, 0))
for Class in polyhedra_classes
]
curr_mob = polyhedra.pop()
for mob in polyhedra:
self.play(TransformAnimations(
2015-05-24 09:42:28 -07:00
Rotating(curr_mob, **rot_kwargs),
Rotating(mob, **rot_kwargs)
))
for m in polyhedra:
m.rotate(rot_kwargs["radians"], rot_kwargs["axis"])
self.play(Rotating(curr_mob, **rot_kwargs))
2015-05-24 09:42:28 -07:00
class ExplainNChoose2Formula(Scene):
args_list = [(7,2,6)]
@staticmethod
def args_to_string(n, a, b):
return "n=%d_a=%d_b=%d"%(n, a, b)
def __init__(self, n, a, b, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
r_paren, a_mob, comma, b_mob, l_paren = TexMobjects(
2015-05-24 09:42:28 -07:00
("( %d , %d )"%(a, b)).split(" ")
)
parens = Mobject(r_paren, comma, l_paren)
nums = [TexMobject(str(k)) for k in range(1, n+1)]
2015-05-24 09:42:28 -07:00
height = 1.5*nums[0].get_height()
for x in range(n):
nums[x].shift((0, x*height, 0))
nums_compound = Mobject(*nums)
2015-05-24 09:42:28 -07:00
nums_compound.shift(a_mob.get_center() - nums[0].get_center())
n_mob, n_minus_1, over_2 = TexMobject([
2015-05-24 09:42:28 -07:00
str(n), "(%d-1)"%n, r"\over{2}"
2015-06-27 04:49:10 -07:00
]).split()
2015-05-24 09:42:28 -07:00
for part in n_mob, n_minus_1, over_2:
part.shift((FRAME_X_RADIUS-1.5, FRAME_Y_RADIUS-1, 0))
2015-05-24 09:42:28 -07:00
self.add(parens, n_mob)
up_unit = np.array((0, height, 0))
self.play(ApplyMethod(nums_compound.shift, -(n-1)*up_unit))
self.play(ApplyMethod(nums_compound.shift, (n-a)*up_unit))
2015-05-24 09:42:28 -07:00
self.remove(nums_compound)
nums = nums_compound.split()
a_mob = nums.pop(a-1)
nums_compound = Mobject(*nums)
2015-05-24 09:42:28 -07:00
self.add(a_mob, nums_compound)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-24 09:42:28 -07:00
right_shift = b_mob.get_center() - a_mob.get_center()
right_shift[1] = 0
self.play(
2015-05-24 09:42:28 -07:00
ApplyMethod(nums_compound.shift, right_shift),
FadeIn(n_minus_1)
)
self.play(ApplyMethod(nums_compound.shift, (a-b)*up_unit))
2015-05-24 09:42:28 -07:00
self.remove(nums_compound)
nums = nums_compound.split()
b_mob = nums.pop(b-2 if a < b else b-1)
self.add(b_mob)
self.play(*[
CounterclockwiseTransform(
2015-05-24 09:42:28 -07:00
mob,
2018-03-30 11:51:31 -07:00
Point(mob.get_center()).set_color("black")
2015-05-24 09:42:28 -07:00
)
for mob in nums
])
self.play(*[
2015-05-24 09:42:28 -07:00
ApplyMethod(mob.shift, (0, 1, 0))
for mob in (parens, a_mob, b_mob)
2015-05-24 09:42:28 -07:00
])
parens_copy = deepcopy(parens).shift((0, -2, 0))
a_center = a_mob.get_center()
b_center = b_mob.get_center()
a_copy = deepcopy(a_mob).center().shift(b_center - (0, 2, 0))
b_copy = deepcopy(b_mob).center().shift(a_center - (0, 2, 0))
self.add(over_2, deepcopy(a_mob), deepcopy(b_mob))
self.play(
CounterclockwiseTransform(a_mob, a_copy),
CounterclockwiseTransform(b_mob, b_copy),
2015-05-24 09:42:28 -07:00
FadeIn(parens_copy),
FadeIn(TextMobject("is considered the same as"))
2015-05-24 09:42:28 -07:00
)
class ExplainNChoose4Formula(Scene):
args_list = [(7,)]
@staticmethod
def args_to_string(n):
return "n=%d"%n
def __init__(self, n, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
# quad = list(it.combinations(range(1,n+1), 4))[randint(0, choose(n, 4)-1)]
quad = (4, 2, 5, 1)
tuple_mobs = TexMobjects(
2015-05-24 09:42:28 -07:00
("( %d , %d , %d , %d )"%quad).split(" ")
)
quad_mobs = tuple_mobs[1::2]
parens = Mobject(*tuple_mobs[0::2])
form_mobs = TexMobject([
2015-05-24 09:42:28 -07:00
str(n), "(%d-1)"%n, "(%d-2)"%n,"(%d-3)"%n,
r"\over {4 \cdot 3 \cdot 2 \cdot 1}"
2015-06-27 04:49:10 -07:00
]).split()
form_mobs = Mobject(*form_mobs).scale(0.7).shift((4, 3, 0)).split()
nums = [TexMobject(str(k)) for k in range(1, n+1)]
2015-05-24 09:42:28 -07:00
height = 1.5*nums[0].get_height()
for x in range(n):
nums[x].shift((0, x*height, 0))
nums_compound = Mobject(*nums)
2015-05-24 09:42:28 -07:00
nums_compound.shift(quad_mobs[0].get_center() - nums[0].get_center())
curr_num = 1
self.add(parens)
up_unit = np.array((0, height, 0))
for i in range(4):
self.add(form_mobs[i])
self.play(ApplyMethod(
2015-05-24 09:42:28 -07:00
nums_compound.shift, (curr_num-quad[i])*up_unit))
self.remove(nums_compound)
nums = nums_compound.split()
chosen = nums[quad[i]-1]
2018-03-30 11:51:31 -07:00
nums[quad[i]-1] = Point(chosen.get_center()).set_color("black")
nums_compound = Mobject(*nums)
2015-05-24 09:42:28 -07:00
self.add(chosen)
if i < 3:
right_shift = quad_mobs[i+1].get_center() - chosen.get_center()
right_shift[1] = 0
self.play(
2015-05-24 09:42:28 -07:00
ApplyMethod(nums_compound.shift, right_shift)
)
else:
self.play(*[
CounterclockwiseTransform(
2015-05-24 09:42:28 -07:00
mob,
2018-03-30 11:51:31 -07:00
Point(mob.get_center()).set_color("black")
2015-05-24 09:42:28 -07:00
)
for mob in nums
])
curr_num = quad[i]
self.remove(*self.mobjects)
num_perms_explain = TextMobject(
2015-05-24 09:42:28 -07:00
r"There are $(4 \cdot 3 \cdot 2 \cdot 1)$ total permutations"
).shift((0, -2, 0))
self.add(parens, num_perms_explain, *form_mobs)
2018-08-09 17:56:05 -07:00
perms = list(it.permutations(list(range(4))))
2015-05-24 09:42:28 -07:00
for count in range(6):
perm = perms[randint(0, 23)]
new_quad_mobs = [
deepcopy(quad_mobs[i]).shift(
quad_mobs[perm[i]].get_center() - \
quad_mobs[i].get_center()
)
for i in range(4)
]
compound_quad = Mobject(*quad_mobs)
self.play(CounterclockwiseTransform(
2015-05-24 09:42:28 -07:00
compound_quad,
Mobject(*new_quad_mobs)
2015-05-24 09:42:28 -07:00
))
self.remove(compound_quad)
quad_mobs = new_quad_mobs
class IntersectionChoppingExamples(Scene):
def __init__(self, *args, **kwargs):
Scene.__init__(self, *args, **kwargs)
pairs1 = [
((-1,-1, 0), (-1, 0, 0)),
((-1, 0, 0), (-1, 1, 0)),
((-2, 0, 0), (-1, 0, 0)),
((-1, 0, 0), ( 1, 0, 0)),
(( 1, 0, 0), ( 2, 0, 0)),
(( 1,-1, 0), ( 1, 0, 0)),
(( 1, 0, 0), ( 1, 1, 0)),
]
pairs2 = pairs1 + [
(( 1, 1, 0), ( 1, 2, 0)),
(( 0, 1, 0), ( 1, 1, 0)),
(( 1, 1, 0), ( 2, 1, 0)),
]
for pairs, exp in [(pairs1, "3 + 2(2) = 7"),
(pairs2, "4 + 2(3) = 10")]:
lines = [Line(*pair).scale(2) for pair in pairs]
self.add(TexMobject(exp).shift((0, FRAME_Y_RADIUS-1, 0)))
2015-05-24 09:42:28 -07:00
self.add(*lines)
2018-01-15 19:15:05 -08:00
self.wait()
self.play(*[
2015-05-24 09:42:28 -07:00
Transform(line, deepcopy(line).scale(1.2).scale_in_place(1/1.2))
for line in lines
])
self.count(lines, run_time = 3.0, num_offset = ORIGIN)
2018-01-15 19:15:05 -08:00
self.wait()
2015-05-24 09:42:28 -07:00
self.remove(*self.mobjects)