Halfway through eop/independence project

This commit is contained in:
Grant Sanderson
2017-07-20 13:37:12 -07:00
parent 820ed83635
commit 62a7df7075
7 changed files with 1305 additions and 16 deletions

File diff suppressed because it is too large Load Diff

View File

@ -161,6 +161,11 @@ class TexMobject(SVGMobject):
part.highlight(color) part.highlight(color)
return self return self
def highlight_by_tex_to_color_map(self, tex_to_color_map):
for tex, color in tex_to_color_map.items():
self.highlight_by_tex(tex, color)
return self
def index_of_part(self, part): def index_of_part(self, part):
split_self = self.split() split_self = self.split()
if part not in split_self: if part not in split_self:

View File

@ -201,7 +201,6 @@ class PiCreature(SVGMobject):
body.copy().pointwise_become_partial(body, *alpha_range) body.copy().pointwise_become_partial(body, *alpha_range)
for alpha_range in self.right_arm_range, self.left_arm_range for alpha_range in self.right_arm_range, self.left_arm_range
]) ])
def get_all_pi_creature_modes(): def get_all_pi_creature_modes():
result = [] result = []
@ -588,7 +587,7 @@ class PiCreatureScene(Scene):
class TeacherStudentsScene(PiCreatureScene): class TeacherStudentsScene(PiCreatureScene):
CONFIG = { CONFIG = {
"student_colors" : [BLUE_D, BLUE_C, BLUE_E], "student_colors" : [BLUE_D, BLUE_E, BLUE_C],
"student_scale_factor" : 0.8, "student_scale_factor" : 0.8,
"seconds_to_blink" : 2, "seconds_to_blink" : 2,
} }

View File

@ -92,8 +92,8 @@ class PascalsTriangle(VMobject):
"portion_to_fill" : 0.7 "portion_to_fill" : 0.7
} }
def generate_points(self): def generate_points(self):
self.cell_height = self.height / self.nrows self.cell_height = float(self.height) / self.nrows
self.cell_width = self.width / self.nrows self.cell_width = float(self.width) / self.nrows
self.bottom_left = (self.cell_width * self.nrows / 2.0)*LEFT + \ self.bottom_left = (self.cell_width * self.nrows / 2.0)*LEFT + \
(self.cell_height * self.nrows / 2.0)*DOWN (self.cell_height * self.nrows / 2.0)*DOWN
num_to_num_mob = {} num_to_num_mob = {}

View File

@ -40,7 +40,7 @@ class OpeningQuote(Scene):
if isinstance(self.quote, str): if isinstance(self.quote, str):
quote = TextMobject("``%s''"%self.quote.strip(), **text_mobject_kwargs) quote = TextMobject("``%s''"%self.quote.strip(), **text_mobject_kwargs)
else: else:
words = ["``"] + list(self.quote) + ["''"] words = ["\\Large ``"] + list(self.quote) + ["''"]
quote = TextMobject(*words, **text_mobject_kwargs) quote = TextMobject(*words, **text_mobject_kwargs)
##TODO, make less hacky ##TODO, make less hacky
if self.quote_arg_separator == " ": if self.quote_arg_separator == " ":
@ -54,7 +54,7 @@ class OpeningQuote(Scene):
return quote return quote
def get_author(self, quote): def get_author(self, quote):
author = TextMobject("-" + self.author) author = TextMobject("\\Large -" + self.author)
author.next_to(quote, DOWN) author.next_to(quote, DOWN)
author.highlight(YELLOW) author.highlight(YELLOW)
return author return author

View File

@ -38,7 +38,6 @@ class Arc(VMobject):
self.highlight(self.get_color()) self.highlight(self.get_color())
return self return self
class Circle(Arc): class Circle(Arc):
CONFIG = { CONFIG = {
"color" : RED, "color" : RED,
@ -48,7 +47,7 @@ class Circle(Arc):
def __init__(self, **kwargs): def __init__(self, **kwargs):
Arc.__init__(self, 2*np.pi, **kwargs) Arc.__init__(self, 2*np.pi, **kwargs)
class Dot(Circle): #Use 1D density, even though 2D class Dot(Circle):
CONFIG = { CONFIG = {
"radius" : 0.08, "radius" : 0.08,
"stroke_width" : 0, "stroke_width" : 0,
@ -60,7 +59,6 @@ class Dot(Circle): #Use 1D density, even though 2D
self.shift(point) self.shift(point)
self.init_colors() self.init_colors()
class Line(VMobject): class Line(VMobject):
CONFIG = { CONFIG = {
"buff" : 0, "buff" : 0,
@ -187,7 +185,6 @@ class DashedLine(Line):
else: else:
return self.end return self.end
class Arrow(Line): class Arrow(Line):
CONFIG = { CONFIG = {
"color" : YELLOW_C, "color" : YELLOW_C,
@ -298,7 +295,6 @@ class RegularPolygon(Polygon):
vertices = compass_directions(n, start_vect) vertices = compass_directions(n, start_vect)
Polygon.__init__(self, *vertices, **kwargs) Polygon.__init__(self, *vertices, **kwargs)
class Rectangle(VMobject): class Rectangle(VMobject):
CONFIG = { CONFIG = {
"color" : WHITE, "color" : WHITE,
@ -360,7 +356,6 @@ class BackgroundRectangle(SurroundingRectangle):
def get_fill_color(self): def get_fill_color(self):
return Color(self.color) return Color(self.color)
class FullScreenFadeRectangle(Rectangle): class FullScreenFadeRectangle(Rectangle):
CONFIG = { CONFIG = {
"height" : 2*SPACE_HEIGHT, "height" : 2*SPACE_HEIGHT,

View File

@ -149,7 +149,6 @@ class SampleSpaceScene(Scene):
]) ])
return anims return anims
class SampleSpace(Rectangle): class SampleSpace(Rectangle):
CONFIG = { CONFIG = {
"height" : 3, "height" : 3,
@ -161,9 +160,6 @@ class SampleSpace(Rectangle):
## ##
"default_label_scale_val" : 1, "default_label_scale_val" : 1,
} }
# def __init__(self, **kwargs):
# Rectangle.__init__(self, **kwargs)
def add_title(self, title = "Sample space", buff = MED_SMALL_BUFF): def add_title(self, title = "Sample space", buff = MED_SMALL_BUFF):
##TODO, should this really exist in SampleSpaceScene ##TODO, should this really exist in SampleSpaceScene
title_mob = TextMobject(title) title_mob = TextMobject(title)
@ -283,6 +279,91 @@ class SampleSpace(Rectangle):
return self.vertical_parts[index] return self.vertical_parts[index]
return self.split()[index] return self.split()[index]
class BarChart(VGroup):
CONFIG = {
"height" : 4,
"width" : 6,
"n_ticks" : 4,
"tick_width" : 0.2,
"label_y_axis" : True,
"y_axis_label_height" : 0.25,
"max_value" : 1,
"bar_colors" : [BLUE, YELLOW],
"bar_fill_opacity" : 0.8,
"bar_stroke_width" : 3,
"bar_names" : [],
"bar_label_scale_val" : 0.75,
}
def __init__(self, values, **kwargs):
VGroup.__init__(self, **kwargs)
if self.max_value is None:
self.max_value = max(values)
self.add_axes()
self.add_bars(values)
self.center()
def add_axes(self):
x_axis = Line(self.tick_width*LEFT/2, self.width*RIGHT)
y_axis = Line(MED_LARGE_BUFF*DOWN, self.height*UP)
ticks = VGroup()
labels = VGroup()
heights = np.linspace(0, self.height, self.n_ticks+1)
values = np.linspace(0, self.max_value, self.n_ticks+1)
for y, value in zip(heights, values):
tick = Line(LEFT, RIGHT)
tick.scale_to_fit_width(self.tick_width)
tick.move_to(y*UP)
ticks.add(tick)
label = TexMobject(str(np.round(value, 2)))
label.scale_to_fit_height(self.y_axis_label_height)
label.next_to(tick, LEFT, SMALL_BUFF)
labels.add(label)
y_axis.add(ticks)
self.add(x_axis, y_axis, labels)
self.x_axis, self.y_axis = x_axis, y_axis
self.y_axis_labels = labels
def add_bars(self, values):
buff = float(self.width) / (2*len(values) + 1)
bars = VGroup()
for i, value in enumerate(values):
bar = Rectangle(
height = (value/self.max_value)*self.height,
width = buff,
stroke_width = self.bar_stroke_width,
fill_opacity = self.bar_fill_opacity,
)
bar.move_to((2*i+1)*buff*RIGHT, DOWN+LEFT)
bars.add(bar)
bars.gradient_highlight(*self.bar_colors)
bar_labels = VGroup()
for bar, name in zip(bars, self.bar_names):
label = TexMobject(str(name))
label.scale(self.bar_label_scale_val)
label.next_to(bar, DOWN, SMALL_BUFF)
bar_labels.add(label)
self.add(bars, bar_labels)
self.bars = bars
self.bar_labels = bar_labels
def change_bar_values(self, values):
for bar, value in zip(self.bars, values):
bar_bottom = bar.get_bottom()
bar.stretch_to_fit_height(
(value/self.max_value)*self.height
)
bar.move_to(bar_bottom, DOWN)
def copy(self):
return self.deepcopy()
### Cards ### ### Cards ###
class DeckOfCards(VGroup): class DeckOfCards(VGroup):