Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easily animate x and y range in a plot and crop NumberPlane #3804

Open
ReneTC opened this issue Jun 12, 2024 · 1 comment
Open

Easily animate x and y range in a plot and crop NumberPlane #3804

ReneTC opened this issue Jun 12, 2024 · 1 comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)

Comments

@ReneTC
Copy link

ReneTC commented Jun 12, 2024

Description of proposed feature

I think it would be usefull to be able to something like:

        plane = always_redraw(lambda:
            NumberPlane(
                y_range = (0, 5),

        )
      self.play(plane.y_range(0,2))

to be able to animate a new axis. It's kinda like zooming in. Currently we must do something like:

class Test(Scene):
    def construct(self):
        x_max = ValueTracker(5)

        plane = always_redraw(lambda:
            NumberPlane(
                x_range = (0, 7),
                y_range = (0, x_max.get_value()),
                x_length = 7,
                y_length = 5,
                axis_config={"include_numbers": True},
            )
        )

        line_graph = always_redraw(lambda:
            NumberPlane(
                x_range = (0, 7),
                y_range = (0, x_max.get_value()),
                x_length = 7,
                y_length = 5,
                axis_config={"include_numbers": True},
            ).plot_line_graph(
                x_values = [0, 1.5, 2, 2.8, 4, 6.25],
                y_values = [1, 3, 2.25, 4, 2.5, 1.75],
                line_color=WHITE,
                vertex_dot_style=dict(stroke_width=3,  fill_color=WHITE),
                stroke_width = 4,
            )
        )
        self.add(plane)
        self.add(line_graph)
        self.wait()
        self.play(x_max.animate.set_value(2), run_time=1)
        self.wait()

This was made by the brilliant Uwezi on the discord forum here.

result:

scriptoutput.mp4

I also think NumberPlane should crop the lines automatically, when going out of the numberPLane

@ReneTC ReneTC added the new feature Enhancement specifically adding a new feature (feature request should be used for issues instead) label Jun 12, 2024
@uwezi
Copy link
Contributor

uwezi commented Jun 12, 2024

Just to highlight part of the problem, the following code referencing the always_redrawn number plane in the updater for the plotted curve does not work - the number plane scales as expected, but the curve is not replotted according to the new scale.

class Test(Scene):
    def construct(self):
        x_max = ValueTracker(5)

        plane = always_redraw(lambda:
            NumberPlane(
                x_range = (0, 7),
                y_range = (0, x_max.get_value()),
                x_length = 7,
                y_length = 5,
                axis_config={"include_numbers": True},
            )
        )

        line_graph = always_redraw(lambda:
            plane.plot_line_graph(
                x_values = [0, 1.5, 2, 2.8, 4, 6.25],
                y_values = [1, 3, 2.25, 4, 2.5, 1.75],
                line_color=WHITE,
                vertex_dot_style=dict(stroke_width=3,  fill_color=WHITE),
                stroke_width = 4,
            )
        )
        self.add(plane)
        self.add(line_graph)
        self.wait()
        self.play(x_max.animate.set_value(2), run_time=1)
        self.wait()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature Enhancement specifically adding a new feature (feature request should be used for issues instead)
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants