There is right part inverse proportional function (1/x) in the scene, in the begining I draw a rectangle(using polygon), the left down corner is (0, 0, 0), thei right up corner is on the function with x=3.
I override update_mobjects, and update the postion of the right upper corner of rectangle with some point on the function, but not work, the width increase instead of decrease, please help, thanks!
my code is as below:
class Chess(GraphScene):
CONFIG = {
"x_min": -5,
"x_max": 5,
"y_min": -5,
"y_max": 6,
"y_axis_height": 10,
"graph_origin": ORIGIN,
"x_labeled_nums": range(-5, 5, 1),
"y_labeled_nums": range(-5, 6, 1)
}
def construct(self):
self.setup_axes(animate=True)
if1r = self.get_graph(lambda x: 1 / x, color=YELLOW_D, x_min=1 / self.y_max, x_max=self.x_max)
self.play(FadeIn(if1r))
spt1 = self.input_to_graph_point(3, if1r)
sg = Polygon(np.array([0, 0, 0]), np.array([spt1[0], 0, 0]), spt1, np.array([0, spt1[1], 0]), fill_color=RED_D,
fill_opacity=1.0)
self.add(sg)
self.sg = sg
self.sva1 = 3
self.if1r = if1r
self.moving3()
def moving3(self):
self.always_update_mobjects = True
self.wait(10)
def update_mobjects(self, dt):
if (hasattr(self, "sva1") and self.sva1 > 1):
self.sva1 = self.sva1 - 0.01
spt2 = self.input_to_graph_point(self.sva1, self.if1r)
self.sg.set
self.sg.set_width(spt2[0], stretch=False, about_point=self.sg.get_corner(DOWN + LEFT))
self.sg.set_height(spt2[1], stretch=False, about_point=self.sg.get_corner(DOWN+LEFT))