Moved Hilbert project out of main directory

This commit is contained in:
Grant Sanderson 2016-01-26 10:22:29 -08:00
parent 0af9b3005c
commit 9705f03c15
6 changed files with 0 additions and 2841 deletions

View file

View file

@ -1,347 +0,0 @@
from mobject import Mobject, Point, Mobject1D
from scene import Scene
from animation.transform import \
Transform, ShimmerIn, FadeIn, FadeOut, ApplyMethod
from animation.simple_animations import \
ShowCreation, DelayByOrder
from topics.geometry import Line, Arc, Arrow
from mobject.tex_mobject import TexMobject, TextMobject
from helpers import *
from hilbert.curves import *
class Intro(TransformOverIncreasingOrders):
@staticmethod
def args_to_string(*args):
return ""
@staticmethod
def string_to_args(string):
raise Exception("string_to_args Not Implemented!")
def construct(self):
words1 = TextMobject(
"If you watched my video about Hilbert's space-filling curve\\dots"
)
words2 = TextMobject(
"\\dots you might be curious to see what a few other space-filling curves look like."
)
words2.scale(0.8)
for words in words1, words2:
words.to_edge(UP, buff = 0.2)
self.setup(HilbertCurve)
self.play(ShimmerIn(words1))
for x in range(4):
self.increase_order()
self.remove(words1)
self.increase_order(
ShimmerIn(words2)
)
for x in range(4):
self.increase_order()
class BringInPeano(Intro):
def construct(self):
words1 = TextMobject("""
For each one, see if you can figure out what
the pattern of construction is.
""")
words2 = TextMobject("""
This one is the Peano curve.
""")
words3 = TextMobject("""
It is the original space-filling curve.
""")
self.setup(PeanoCurve)
self.play(ShimmerIn(words1))
self.dither(5)
self.remove(words1)
self.add(words2.to_edge(UP))
for x in range(3):
self.increase_order()
self.remove(words2)
self.increase_order(ShimmerIn(words3.to_edge(UP)))
for x in range(2):
self.increase_order()
class FillOtherShapes(Intro):
def construct(self):
words1 = TextMobject("""
But of course, there's no reason we should limit
ourselves to filling in squares.
""")
words2 = TextMobject("""
Here's a simple triangle-filling curve I defined
in a style reflective of a Hilbert curve.
""")
words1.to_edge(UP)
words2.scale(0.8).to_edge(UP, buff = 0.2)
self.setup(TriangleFillingCurve)
self.play(ShimmerIn(words1))
for x in range(3):
self.increase_order()
self.remove(words1)
self.add(words2)
for x in range(5):
self.increase_order()
class SmallerFlowSnake(FlowSnake):
DEFAULT_CONFIG = {
"radius" : 4
}
class MostDelightfulName(Intro):
def construct(self):
words1 = TextMobject("""
This one has the most delightful name,
thanks to mathematician/programmer Bill Gosper:
""")
words2 = TextMobject("``Flow Snake''")
words3 = TextMobject("""
What makes this one particularly interesting
is that the boundary itself is a fractal.
""")
for words in words1, words2, words3:
words.to_edge(UP)
self.setup(SmallerFlowSnake)
self.play(ShimmerIn(words1))
for x in range(3):
self.increase_order()
self.remove(words1)
self.add(words2)
for x in range(3):
self.increase_order()
self.remove(words2)
self.play(ShimmerIn(words3))
class SurpriseFractal(Intro):
def construct(self):
words = TextMobject("""
It might come as a surprise how some well-known
fractals can be described with curves.
""")
words.to_edge(UP)
self.setup(Sierpinski)
self.add(TextMobject("Speaking of other fractals\\dots"))
self.dither(3)
self.clear()
self.play(ShimmerIn(words))
for x in range(9):
self.increase_order()
class IntroduceKoch(Intro):
def construct(self):
words = map(TextMobject, [
"This is another famous fractal.",
"The ``Koch Snowflake''",
"Let's finish things off by seeing how to turn \
this into a space-filling curve"
])
for text in words:
text.to_edge(UP)
self.setup(KochCurve)
self.add(words[0])
for x in range(3):
self.increase_order()
self.remove(words[0])
self.add(words[1])
for x in range(4):
self.increase_order()
self.remove(words[1])
self.add(words[2])
self.dither(6)
class StraightKoch(KochCurve):
DEFAULT_CONFIG = {
"axiom" : "A"
}
class SharperKoch(StraightKoch):
DEFAULT_CONFIG = {
"angle" : 0.9*np.pi/2,
}
class DullerKoch(StraightKoch):
DEFAULT_CONFIG = {
"angle" : np.pi/6,
}
class SpaceFillingKoch(StraightKoch):
DEFAULT_CONFIG = {
"angle" : np.pi/2,
}
class FromKochToSpaceFilling(Scene):
def construct(self):
self.max_order = 7
self.revisit_koch()
self.show_angles()
self.show_change_side_by_side()
def revisit_koch(self):
words = map(TextMobject, [
"First, look at how one section of this curve is made.",
"This pattern of four lines is the ``seed''",
"With each iteration, every straight line is \
replaced with an appropriately small copy of the seed",
])
for text in words:
text.to_edge(UP)
self.add(words[0])
curve = StraightKoch(order = self.max_order)
self.play(Transform(
curve,
StraightKoch(order = 1),
run_time = 5
))
self.remove(words[0])
self.add(words[1])
self.dither(4)
self.remove(words[1])
self.add(words[2])
self.dither(3)
for order in range(2, self.max_order):
self.play(Transform(
curve,
StraightKoch(order = order)
))
if order == 2:
self.dither(2)
elif order == 3:
self.dither()
self.clear()
def show_angles(self):
words = TextMobject("""
Let's see what happens as we change
the angle in this seed
""")
words.to_edge(UP)
koch, sharper_koch, duller_koch = curves = [
CurveClass(order = 1)
for CurveClass in StraightKoch, SharperKoch, DullerKoch
]
arcs = [
Arc(
2*(np.pi/2 - curve.angle),
radius = r,
start_angle = np.pi+curve.angle
).shift(curve.points[curve.get_num_points()/2])
for curve, r in zip(curves, [0.6, 0.7, 0.4])
]
theta = TexMobject("\\theta")
theta.shift(arcs[0].get_center()+2.5*DOWN)
arrow = Arrow(theta, arcs[0])
self.add(words, koch)
self.play(ShowCreation(arcs[0]))
self.play(
ShowCreation(arrow),
ShimmerIn(theta)
)
self.dither(2)
self.remove(theta, arrow)
self.play(
Transform(koch, duller_koch),
Transform(arcs[0], arcs[2]),
)
self.play(
Transform(koch, sharper_koch),
Transform(arcs[0], arcs[1]),
)
self.clear()
def show_change_side_by_side(self):
seed = TextMobject("Seed")
seed.shift(3*LEFT+2*DOWN)
fractal = TextMobject("Fractal")
fractal.shift(3*RIGHT+2*DOWN)
words = map(TextMobject, [
"A sharper angle results in a richer curve",
"A more obtuse angle gives a sparser curve",
"And as the angle approaches 0\\dots",
"We have a new space-filling curve."
])
for text in words:
text.to_edge(UP)
sharper, duller, space_filling = [
CurveClass(order = 1).shift(3*LEFT)
for CurveClass in SharperKoch, DullerKoch, SpaceFillingKoch
]
shaper_f, duller_f, space_filling_f = [
CurveClass(order = self.max_order).shift(3*RIGHT)
for CurveClass in SharperKoch, DullerKoch, SpaceFillingKoch
]
self.add(words[0])
left_curve = SharperKoch(order = 1)
right_curve = SharperKoch(order = 1)
self.play(
Transform(left_curve, sharper),
ApplyMethod(right_curve.shift, 3*RIGHT),
)
self.play(
Transform(
right_curve,
SharperKoch(order = 2).shift(3*RIGHT)
),
ShimmerIn(seed),
ShimmerIn(fractal)
)
for order in range(3, self.max_order):
self.play(Transform(
right_curve,
SharperKoch(order = order).shift(3*RIGHT)
))
self.remove(words[0])
self.add(words[1])
kwargs = {
"run_time" : 4,
}
self.play(
Transform(left_curve, duller, **kwargs),
Transform(right_curve, duller_f, **kwargs)
)
self.dither()
kwargs["run_time"] = 7
kwargs["rate_func"] = None
self.remove(words[1])
self.add(words[2])
self.play(
Transform(left_curve, space_filling, **kwargs),
Transform(right_curve, space_filling_f, **kwargs)
)
self.remove(words[2])
self.add(words[3])
self.dither()

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,310 +0,0 @@
from mobject import Mobject, Point
from mobject.tex_mobject import \
TexMobject, TextMobject, Brace
from mobject.image_mobject import \
ImageMobject, MobjectFromRegion
from scene import Scene
from animation import Animation
from animation.transform import \
Transform, CounterclockwiseTransform, ApplyMethod,\
GrowFromCenter, ClockwiseTransform, ApplyPointwiseFunction,\
TransformAnimations, ShimmerIn, FadeOut, FadeIn
from animation.simple_animations import \
ShowCreation, DelayByOrder
from animation.playground import Vibrate
from topics.geometry import \
Line, Dot, Arrow, Grid, Square, Point, Polygon
from topics.characters import \
ThoughtBubble, SpeechBubble, Mathematician, Mortimer
from topics.number_line import UnitInterval
from topics.three_dimensions import Stars
from region import region_from_polygon_vertices
import displayer as disp
from hilbert.curves import \
TransformOverIncreasingOrders, FlowSnake, HilbertCurve, \
SnakeCurve, Sierpinski
from hilbert.section1 import get_mathy_and_bubble
from helpers import *
class SectionThree(Scene):
def construct(self):
self.add(TextMobject("A few words on the usefulness of infinite math"))
self.dither()
class InfiniteResultsFiniteWorld(Scene):
def construct(self):
left_words = TextMobject("Infinite result")
right_words = TextMobject("Finite world")
for words in left_words, right_words:
words.scale(0.8)
left_formula = TexMobject(
"\\sum_{n = 0}^{\\infty} 2^n = -1"
)
right_formula = TexMobject("111\\cdots111")
for formula in left_formula, right_formula:
formula.add(
Brace(formula, UP),
)
formula.ingest_sub_mobjects()
right_overwords = TextMobject(
"\\substack{\
\\text{How computers} \\\\ \
\\text{represent $-1$}\
}"
).scale(1.5)
left_mobs = [left_words, left_formula]
right_mobs = [right_words, right_formula]
for mob in left_mobs:
mob.to_edge(RIGHT, buff = 1)
mob.shift(SPACE_WIDTH*LEFT)
for mob in right_mobs:
mob.to_edge(LEFT, buff = 1)
mob.shift(SPACE_WIDTH*RIGHT)
arrow = Arrow(left_words, right_words)
right_overwords.next_to(right_formula, UP)
self.play(ShimmerIn(left_words))
self.play(ShowCreation(arrow))
self.play(ShimmerIn(right_words))
self.dither()
self.play(
ShimmerIn(left_formula),
ApplyMethod(left_words.next_to, left_formula, UP)
)
self.dither()
self.play(
ShimmerIn(right_formula),
Transform(right_words, right_overwords)
)
self.dither()
self.finite_analog(
Mobject(left_formula, left_words),
arrow,
Mobject(right_formula, right_words)
)
def finite_analog(self, left_mob, arrow, right_mob):
self.clear()
self.add(left_mob, arrow, right_mob)
ex = TextMobject("\\times")
ex.highlight(RED)
# ex.shift(arrow.get_center())
middle = TexMobject(
"\\sum_{n=0}^N 2^n \\equiv -1 \\mod 2^{N+1}"
)
finite_analog = TextMobject("Finite analog")
finite_analog.scale(0.8)
brace = Brace(middle, UP)
finite_analog.next_to(brace, UP)
new_left = left_mob.copy().to_edge(LEFT)
new_right = right_mob.copy().to_edge(RIGHT)
left_arrow, right_arrow = [
Arrow(
mob1.get_right()[0]*RIGHT,
mob2.get_left()[0]*RIGHT,
buff = 0
)
for mob1, mob2 in [
(new_left, middle),
(middle, new_right)
]
]
for mob in ex, middle:
mob.sort_points(np.linalg.norm)
self.play(GrowFromCenter(ex))
self.dither()
self.play(
Transform(left_mob, new_left),
Transform(arrow.copy(), left_arrow),
DelayByOrder(Transform(ex, middle)),
Transform(arrow, right_arrow),
Transform(right_mob, new_right)
)
self.play(
GrowFromCenter(brace),
ShimmerIn(finite_analog)
)
self.dither()
self.equivalence(
left_mob,
left_arrow,
Mobject(middle, brace, finite_analog)
)
def equivalence(self, left_mob, arrow, right_mob):
self.clear()
self.add(left_mob, arrow, right_mob)
words = TextMobject("is equivalent to")
words.shift(0.25*LEFT)
words.highlight(BLUE)
new_left = left_mob.copy().shift(RIGHT)
new_right = right_mob.copy()
new_right.shift(
(words.get_right()[0]-\
right_mob.get_left()[0]+\
0.5
)*RIGHT
)
for mob in arrow, words:
mob.sort_points(np.linalg.norm)
self.play(
ApplyMethod(left_mob.shift, RIGHT),
Transform(arrow, words),
ApplyMethod(right_mob.to_edge, RIGHT)
)
self.dither()
class HilbertCurvesStayStable(Scene):
def construct(self):
scale_factor = 0.9
grid = Grid(4, 4, point_thickness = 1)
curve = HilbertCurve(order = 2)
for mob in grid, curve:
mob.scale(scale_factor)
words = TextMobject("""
Sequence of curves is stable
$\\leftrightarrow$ existence of limit curve
""", size = "\\normal")
words.scale(1.25)
words.to_edge(UP)
self.add(curve, grid)
self.dither()
for n in range(3, 7):
if n == 5:
self.play(ShimmerIn(words))
new_grid = Grid(2**n, 2**n, point_thickness = 1)
new_curve = HilbertCurve(order = n)
for mob in new_grid, new_curve:
mob.scale(scale_factor)
self.play(
ShowCreation(new_grid),
Animation(curve)
)
self.remove(grid)
grid = new_grid
self.play(Transform(curve, new_curve))
self.dither()
class InfiniteObjectsEncapsulateFiniteObjects(Scene):
def get_triangles(self):
triangle = Polygon(
LEFT/np.sqrt(3),
UP,
RIGHT/np.sqrt(3),
color = GREEN
)
triangles = Mobject(
triangle.copy().scale(0.5).shift(LEFT),
triangle,
triangle.copy().scale(0.3).shift(0.5*UP+RIGHT)
)
triangles.center()
return triangles
def construct(self):
words =[
TextMobject(text, size = "\\large")
for text in [
"Truths about infinite objects",
" encapsulate ",
"facts about finite objects"
]
]
words[0].highlight(RED)
words[1].next_to(words[0])
words[2].highlight(GREEN).next_to(words[1])
Mobject(*words).center().to_edge(UP)
infinite_objects = [
TexMobject(
"\\sum_{n=0}^\\infty",
size = "\\normal"
).highlight(RED_E),
Sierpinski(order = 8).scale(0.3),
TextMobject(
"$\\exists$ something infinite $\\dots$"
).highlight(RED_B)
]
finite_objects = [
TexMobject(
"\\sum_{n=0}^N",
size = "\\normal"
).highlight(GREEN_E),
self.get_triangles(),
TextMobject(
"$\\forall$ finite somethings $\\dots$"
).highlight(GREEN_B)
]
for infinite, finite, n in zip(infinite_objects, finite_objects, it.count(1, 2)):
infinite.next_to(words[0], DOWN, buff = n)
finite.next_to(words[2], DOWN, buff = n)
self.play(ShimmerIn(words[0]))
self.dither()
self.play(ShimmerIn(infinite_objects[0]))
self.play(ShowCreation(infinite_objects[1]))
self.play(ShimmerIn(infinite_objects[2]))
self.dither()
self.play(ShimmerIn(words[1]), ShimmerIn(words[2]))
self.play(ShimmerIn(finite_objects[0]))
self.play(ShowCreation(finite_objects[1]))
self.play(ShimmerIn(finite_objects[2]))
self.dither()
class StatementRemovedFromReality(Scene):
def construct(self):
mathy, bubble = get_mathy_and_bubble()
bubble.stretch_to_fit_width(4)
mathy.to_corner(DOWN+LEFT)
bubble.pin_to(mathy)
bubble.shift(LEFT)
morty = Mortimer()
morty.to_corner(DOWN+RIGHT)
morty_bubble = SpeechBubble()
morty_bubble.stretch_to_fit_width(4)
morty_bubble.pin_to(morty)
bubble.write("""
Did you know a curve \\\\
can fill all space?
""")
morty_bubble.write("Who cares?")
self.add(mathy, morty)
for bub, buddy in [(bubble, mathy), (morty_bubble, morty)]:
self.play(Transform(
Point(bub.get_tip()),
bub
))
self.play(ShimmerIn(bub.content))
self.play(ApplyMethod(
buddy.blink,
rate_func = squish_rate_func(there_and_back)
))