Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add example PolygonOnAxes (#2610)

Prismodf1a60421ea1
diff --git a/docs/source/examples.rst b/docs/source/examples.rst
index d787c7111..79ed27a9c 100644
--- a/docs/source/examples.rst
+++ b/docs/source/examples.rst
@@ -407,6 +407,64 @@ Plotting with Manim
self.add(ax, labels, curve_1, curve_2, line_1, line_2, riemann_area, area)
+.. manim:: PolygonOnAxes
+ :ref_classes: Axes Polygon
+
+ class PolygonOnAxes(Scene):
+ def get_rectangle_corners(self, bottom_left, top_right):
+ return [
+ (top_right[0], top_right[1]),
+ (bottom_left[0], top_right[1]),
+ (bottom_left[0], bottom_left[0]),
+ (top_right[0], bottom_left[0]),
+ ]
+
+ def construct(self):
+ ax = Axes(
+ x_range=[0, 10],
+ y_range=[0, 10],
+ x_length=6,
+ y_length=6,
+ axis_config={"include_tip": False},
+ )
+
+ t = ValueTracker(5)
+ k = 25
+
+ graph = ax.plot(
+ lambda x: k / x,
+ color=YELLOW_D,
+ x_range=[k / 10, 10.0, 0.01],
+ use_smoothing=False,
+ )
+
+ def get_rectangle():
+ polygon = Polygon(
+ *[
+ ax.c2p(*i)
+ for i in self.get_rectangle_corners(
+ (0, 0), (t.get_value(), k / t.get_value())
+ )
+ ]
+ )
+ polygon.stroke_width = 1
+ polygon.set_fill(BLUE, opacity=0.5)
+ polygon.set_stroke(YELLOW_B)
+ return polygon
+
+ polygon = always_redraw(get_rectangle)
+
+ dot = Dot()
+ dot.add_updater(lambda x: x.move_to(ax.c2p(t.get_value(), k / t.get_value())))
+ dot.set_z_index(10)
+
+ self.add(ax, graph, dot)
+ self.play(Create(polygon))
+ self.play(t.animate.set_value(10))
+ self.play(t.animate.set_value(k / 10))
+ self.play(t.animate.set_value(5))
+
+
.. manim:: HeatDiagramPlot
:save_last_frame:
:ref_modules: manim.mobject.coordinate_systems