About halfway through eoc1 remake

This commit is contained in:
Grant Sanderson
2017-04-04 16:57:53 -07:00
parent 8b12ec879e
commit 0e09120092
5 changed files with 985 additions and 33 deletions

View File

@ -120,8 +120,11 @@ class Animation(object):
def clean_up(self, surrounding_scene = None): def clean_up(self, surrounding_scene = None):
self.update(1) self.update(1)
if self.is_remover() and surrounding_scene is not None: if surrounding_scene is not None:
surrounding_scene.remove(self.mobject) if self.is_remover():
surrounding_scene.remove(self.mobject)
else:
surrounding_scene.add(self.mobject)
return self return self

File diff suppressed because it is too large Load Diff

View File

@ -60,7 +60,6 @@ class Car(SVGMobject):
self.add(orientation_line) self.add(orientation_line)
self.orientation_line = orientation_line self.orientation_line = orientation_line
self.add_treds_to_tires() self.add_treds_to_tires()
def move_to(self, point_or_mobject): def move_to(self, point_or_mobject):

View File

@ -29,6 +29,7 @@ class GraphScene(Scene):
"axes_color" : GREY, "axes_color" : GREY,
"graph_origin" : 2.5*DOWN + 4*LEFT, "graph_origin" : 2.5*DOWN + 4*LEFT,
"y_axis_numbers_nudge" : 0.4*UP, "y_axis_numbers_nudge" : 0.4*UP,
"exclude_zero_label" : True,
"num_graph_anchor_points" : 25, "num_graph_anchor_points" : 25,
"default_graph_colors" : [BLUE, GREEN, YELLOW], "default_graph_colors" : [BLUE, GREEN, YELLOW],
"default_derivative_color" : GREEN, "default_derivative_color" : GREEN,
@ -49,10 +50,12 @@ class GraphScene(Scene):
) )
x_axis.shift(self.graph_origin - x_axis.number_to_point(0)) x_axis.shift(self.graph_origin - x_axis.number_to_point(0))
if len(self.x_labeled_nums) > 0: if len(self.x_labeled_nums) > 0:
x_axis.add_numbers(*filter( if self.exclude_zero_label:
lambda x : x != 0, self.x_labeled_nums = filter(
self.x_labeled_nums lambda x : x != 0,
)) self.x_labeled_nums
)
x_axis.add_numbers(*self.x_labeled_nums)
x_label = TextMobject(self.x_axis_label) x_label = TextMobject(self.x_axis_label)
x_label.next_to( x_label.next_to(
x_axis.get_tick_marks(), UP+RIGHT, x_axis.get_tick_marks(), UP+RIGHT,
@ -77,10 +80,12 @@ class GraphScene(Scene):
y_axis.shift(self.graph_origin-y_axis.number_to_point(0)) y_axis.shift(self.graph_origin-y_axis.number_to_point(0))
y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0)) y_axis.rotate(np.pi/2, about_point = y_axis.number_to_point(0))
if len(self.y_labeled_nums) > 0: if len(self.y_labeled_nums) > 0:
y_axis.add_numbers(*filter( if self.exclude_zero_label:
lambda y : y != 0, self.y_labeled_nums = filter(
self.y_labeled_nums lambda y : y != 0,
)) self.y_labeled_nums
)
y_axis.add_numbers(*self.y_labeled_nums)
for mob in y_axis.numbers: for mob in y_axis.numbers:
mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF) mob.next_to(mob.get_center(), LEFT, MED_SMALL_BUFF)
mob.shift(self.y_axis_numbers_nudge) mob.shift(self.y_axis_numbers_nudge)
@ -184,6 +189,7 @@ class GraphScene(Scene):
x_min = None, x_min = None,
x_max = None, x_max = None,
dx = 0.1, dx = 0.1,
input_sample_type = "left",
stroke_width = 1, stroke_width = 1,
start_color = BLUE, start_color = BLUE,
end_color = GREEN): end_color = GREEN):
@ -191,10 +197,19 @@ class GraphScene(Scene):
x_max = x_max if x_max is not None else self.x_max x_max = x_max if x_max is not None else self.x_max
rectangles = VGroup() rectangles = VGroup()
for x in np.arange(x_min, x_max, dx): for x in np.arange(x_min, x_max, dx):
if input_sample_type == "left":
sample_input = x
elif input_sample_type == "right":
sample_input = x+dx
else:
raise Exception("Invalid input sample type")
graph_point = self.input_to_graph_point(sample_input, graph)
points = VGroup(*map(VectorizedPoint, [ points = VGroup(*map(VectorizedPoint, [
self.coords_to_point(x, 0), self.coords_to_point(x, 0),
self.input_to_graph_point(x+dx, graph) self.coords_to_point(x+dx, 0),
graph_point
])) ]))
rect = Rectangle() rect = Rectangle()
rect.replace(points, stretch = True) rect.replace(points, stretch = True)
rect.set_fill(opacity = 1) rect.set_fill(opacity = 1)

View File

@ -201,6 +201,7 @@ class VMobject(Mobject):
it comes time to display. it comes time to display.
""" """
subpath_mobject = self.copy() ##Really helps to be of the same class subpath_mobject = self.copy() ##Really helps to be of the same class
subpath_mobject.submobjects = []
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)