31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
|
import manim
|
|||
|
from manim import *
|
|||
|
# pip install manim-physics
|
|||
|
# https://manim-physics.readthedocs.io/en/latest/reference/manim_physics.electromagnetism.magnetostatics.MagneticField.html
|
|||
|
from manim_physics import *
|
|||
|
|
|||
|
class MagneticFieldExample(ThreeDScene):
|
|||
|
def construct(self):
|
|||
|
wire = Wire(Circle(2).rotate(PI / 2, UP))
|
|||
|
mag_field = MagneticField(
|
|||
|
wire,
|
|||
|
x_range=[-4, 4],
|
|||
|
y_range=[-4, 4],
|
|||
|
)
|
|||
|
self.set_camera_orientation(PI / 3, PI / 4)
|
|||
|
self.add(wire, mag_field)
|
|||
|
|
|||
|
if __name__ == '__main__':
|
|||
|
# 配置字典说明:
|
|||
|
config = {
|
|||
|
"quality": "low_quality", # 渲染质量等级(low_quality对应480p)
|
|||
|
"preview": True, # 渲染完成后自动打开播放器
|
|||
|
"input_file": __file__, # 指定输入文件为当前文件
|
|||
|
"media_dir": "./custom_output" # 自定义输出目录(默认在media/)
|
|||
|
}
|
|||
|
# 使用临时配置渲染场景(配置只在with块内有效)
|
|||
|
with manim.tempconfig(config):
|
|||
|
# 实例化场景类
|
|||
|
scene = MagneticFieldExample()
|
|||
|
# 执行渲染流程(包含文件生成和预览)
|
|||
|
scene.render()
|