"""A self-contained Manim Community 0.21.0 lesson; no LaTeX required. Render: manim -qm --disable_caching slope_scene.py SlopeLesson """ from manim import ( BLUE, ORANGE, WHITE, Axes, Dot, Line, Scene, Text, ValueTracker, always_redraw, linear, ) class SlopeLesson(Scene): def construct(self): self.camera.background_color = "#111827" axes = Axes( x_range=[-3, 3, 1], y_range=[-5, 5, 1], x_length=9, y_length=4.5, axis_config={"include_tip": False, "color": WHITE}, ).shift([0, -0.1, 0]) title = Text("Changing slope: y = m x", font_size=34).move_to([0, 3.25, 0]) scale_note = Text("Read the values: the x and y screen scales differ.", font_size=20).move_to([0, 2.65, 0]) labels = [Text("x", font_size=23).next_to(axes.x_axis.get_end(), [1, 0, 0]), Text("y", font_size=23).next_to(axes.y_axis.get_end(), [0, 1, 0])] for x in [-2, -1, 1, 2]: labels.append(Text(str(x), font_size=19).move_to(axes.c2p(x, 0) + [0, -0.28, 0])) for y in [-4, -2, 2, 4]: labels.append(Text(str(y), font_size=19).move_to(axes.c2p(0, y) + [-0.3, 0, 0])) m = ValueTracker(0) graph = always_redraw(lambda: Line( axes.c2p(-2, -2 * m.get_value()), axes.c2p(2, 2 * m.get_value()), color=BLUE, stroke_width=5, )) point = always_redraw(lambda: Dot(axes.c2p(2, 2 * m.get_value()), color=ORANGE, radius=0.09)) readout = always_redraw(lambda: Text( f"m = {m.get_value():.1f} x = 2 y = {2 * m.get_value():.1f}", font_size=27, color=ORANGE, ).move_to([0, -2.9, 0])) self.add(axes, title, scale_note, *labels, graph, point, readout) self.wait(2) for target in [1, 2, -1]: self.play(m.animate.set_value(target), run_time=1, rate_func=linear) self.wait(2) self.wait(1)