mirror of
https://github.com/3b1b/manim.git
synced 2025-09-19 04:41:56 +00:00
now both integral bounds can move
This commit is contained in:
parent
bd1c312f3b
commit
83bebfb109
1 changed files with 43 additions and 22 deletions
|
@ -57,6 +57,11 @@ class GraphScene(Scene):
|
|||
def setup(self):
|
||||
self.default_graph_colors_cycle = it.cycle(self.default_graph_colors)
|
||||
|
||||
self.left_T_label = VGroup()
|
||||
self.left_v_line = VGroup()
|
||||
self.right_T_label = VGroup()
|
||||
self.right_v_line = VGroup()
|
||||
|
||||
def setup_axes(self, animate=False):
|
||||
# TODO, once eoc is done, refactor this to be less redundant.
|
||||
x_num_range = float(self.x_max - self.x_min)
|
||||
|
@ -291,7 +296,7 @@ class GraphScene(Scene):
|
|||
|
||||
|
||||
def get_area(self, graph, t_min, t_max):
|
||||
numerator = max(t_max - t_min, 0.01)
|
||||
numerator = max(t_max - t_min, 0.0001)
|
||||
dx = float(numerator) / self.num_rects
|
||||
return self.get_riemann_rectangles(
|
||||
graph,
|
||||
|
@ -439,13 +444,17 @@ class GraphScene(Scene):
|
|||
return group
|
||||
|
||||
|
||||
def add_T_label(self, x_val, color = WHITE, animated = False, **kwargs):
|
||||
def add_T_label(self, x_val, side = RIGHT, label = None, color = WHITE, animated = False, **kwargs):
|
||||
triangle = RegularPolygon(n=3, start_angle = np.pi/2)
|
||||
triangle.scale_to_fit_height(MED_SMALL_BUFF)
|
||||
triangle.move_to(self.coords_to_point(x_val, 0), UP)
|
||||
triangle.set_fill(color, 1)
|
||||
triangle.set_stroke(width = 0)
|
||||
T_label = TexMobject(self.variable_point_label, fill_color = color)
|
||||
if label == None:
|
||||
T_label = TexMobject(self.variable_point_label, fill_color = color)
|
||||
else:
|
||||
T_label = TexMobject(label, fill_color = color)
|
||||
|
||||
T_label.next_to(triangle, DOWN)
|
||||
v_line = self.get_vertical_line_to_graph(
|
||||
x_val, self.v_graph,
|
||||
|
@ -462,8 +471,13 @@ class GraphScene(Scene):
|
|||
else:
|
||||
self.add(triangle, v_line, T_label)
|
||||
|
||||
self.T_label_group = VGroup(T_label, triangle)
|
||||
self.right_v_line = v_line
|
||||
if np.all(side == LEFT):
|
||||
self.left_T_label_group = VGroup(T_label, triangle)
|
||||
self.left_v_line = v_line
|
||||
elif np.all(side == RIGHT):
|
||||
self.right_T_label_group = VGroup(T_label, triangle)
|
||||
self.right_v_line = v_line
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -472,6 +486,7 @@ class GraphScene(Scene):
|
|||
graph,
|
||||
new_t_min,
|
||||
new_t_max,
|
||||
fade_close_to_origin = True,
|
||||
run_time = 1.0
|
||||
):
|
||||
curr_t_min = self.x_axis.point_to_number(self.area.get_left())
|
||||
|
@ -482,33 +497,39 @@ class GraphScene(Scene):
|
|||
new_t_max = curr_t_max
|
||||
|
||||
group = VGroup(self.area)
|
||||
if hasattr(self, "right_v_line"):
|
||||
group.add(self.right_v_line)
|
||||
else:
|
||||
group.add(VGroup())
|
||||
# because update_group expects 3 elements in group
|
||||
if hasattr(self, "T_label_group"):
|
||||
group.add(self.T_label_group)
|
||||
else:
|
||||
group.add(VGroup())
|
||||
group.add(self.left_v_line)
|
||||
group.add(self.left_T_label_group)
|
||||
group.add(self.right_v_line)
|
||||
group.add(self.right_T_label_group)
|
||||
|
||||
def update_group(group, alpha):
|
||||
area, v_line, T_label = group
|
||||
area, left_v_line, left_T_label, right_v_line, right_T_label = group
|
||||
t_min = interpolate(curr_t_min, new_t_min, alpha)
|
||||
t_max = interpolate(curr_t_max, new_t_max, alpha)
|
||||
new_area = self.get_area(graph,t_min, t_max)
|
||||
new_v_line = self.get_vertical_line_to_graph(
|
||||
|
||||
new_left_v_line = self.get_vertical_line_to_graph(
|
||||
t_min, graph
|
||||
)
|
||||
new_left_v_line.set_color(left_v_line.get_color())
|
||||
left_T_label.move_to(new_left_v_line.get_bottom(), UP)
|
||||
|
||||
new_right_v_line = self.get_vertical_line_to_graph(
|
||||
t_max, graph
|
||||
)
|
||||
new_v_line.set_color(v_line.get_color())
|
||||
T_label.move_to(new_v_line.get_bottom(), UP)
|
||||
new_right_v_line.set_color(right_v_line.get_color())
|
||||
right_T_label.move_to(new_right_v_line.get_bottom(), UP)
|
||||
|
||||
#Fade close to 0
|
||||
if len(T_label) > 0:
|
||||
T_label[0].set_fill(opacity = min(1, t_max))
|
||||
# Fade close to 0
|
||||
if fade_close_to_origin:
|
||||
if len(left_T_label) > 0:
|
||||
left_T_label[0].set_fill(opacity = min(1, np.abs(t_min)))
|
||||
if len(right_T_label) > 0:
|
||||
right_T_label[0].set_fill(opacity = min(1, np.abs(t_max)))
|
||||
|
||||
Transform(area, new_area).update(1)
|
||||
Transform(v_line, new_v_line).update(1)
|
||||
Transform(left_v_line, new_left_v_line).update(1)
|
||||
Transform(right_v_line, new_right_v_line).update(1)
|
||||
return group
|
||||
|
||||
return UpdateFromAlphaFunc(group, update_group, run_time = run_time)
|
||||
|
|
Loading…
Add table
Reference in a new issue