manim_zh_doc
  • 如何安装manim
  • 快速使用
  • 最佳实践
    • Basic Concepts
      • ManimCELogo
      • BraceAnnotation
      • VectorArrow
      • GradientImageFromArray
      • BooleanOperations
    • Animations
      • PointMovingOnShapes
      • MovingAround
      • MovingAngle
      • MovingDots
      • MovingGroupToDestination
      • MovingFrameBox
      • RotationUpdater
      • PointWithTrace
    • Plotting
      • SinAndCosFunctionPlot
      • ArgMinExample
      • GraphAreaPlot
      • PolygonOnAxes
      • HeatDiagramPlot
  • 教程 And 指导
    • 快速使用
      • 概述
      • 新建Project
      • 制作动画
      • 解释
      • 正方形转换圆
      • 定位Mobject
      • 使用.animate语法进行动画处理
      • Transform与ReplacementTransform
    • 输出设置
      • Manim 输出文件夹
      • 章节
      • 命令行标志
    • Manim 的构建块
      • Mobjects
        • 创建和显示 mobjects
        • 放置 mobjects
        • 设置 mobject 的样式
        • Mobject 屏幕顺序
      • 动画
        • 制作方法动画
        • 动画运行时间
        • 创建自定义动画
        • 使用 mobject 的坐标
        • 将 mobject 转换为其他 mobject
      • 场景
  • 进阶指南
    • 配置
      • 命令行参数
        • 高级示例
        • 所有 CLI 标志的列表
      • ManimConfig 类
      • 配置文件
    • 深入了解 Manim 的内部结构
      • 介绍
      • 概述
      • Page
Powered by GitBook
On this page
  1. 教程 And 指导
  2. 快速使用

定位Mobject

接下来,让我们回顾一下定位Mobject的一些基本技巧。

  1. 打开 scene.py,并在SquareToCircle方法下方添加以下代码片段:

class SquareAndCircle(Scene):
    def construct(self):
        circle = Circle()  # create a circle
        circle.set_fill(PINK, opacity=0.5)  # set the color and transparency

        square = Square()  # create a square
        square.set_fill(BLUE, opacity=0.5)  # set the color and transparency

        square.next_to(circle, RIGHT, buff=0.5)  # set the position
        self.play(Create(circle), Create(square))  # show the shapes on screen
  1. 通过在命令行中运行以下命令进行渲染SquareAndCircle:

manim -pql scene.py SquareAndCircle

next_to是一种定位Mobject 的方法。

我们首先指定了 粉红色圆圈作为正方形的参考点,circle作为方法的第一个参数Mobject传递。 第二个参数用于指定相对于参考点的放置方向。 在本例中,我们将 direction 设置为 RIGHT,告诉 Manim 将正方形定位在圆的右侧。 最后,在两个对象之间应用一个小的距离缓冲区buff=0.5。

尝试更改RIGHT为LEFT 、 UP或DOWN ,看看它如何改变正方形的位置。

使用定位方法,可以渲染具有多个Mobject 的场景, 使用坐标设置它们在场景中的位置或定位它们相对于彼此。

Previous正方形转换圆Next使用.animate语法进行动画处理

Last updated 22 days ago