Manim Zoom 不保留线宽?
Manim Zoom Not Preserving Line Thickness?
这是一些示例代码的修改版本,来自 this page 的底部。唯一的变化是我添加了一行:
from manimlib.imports import *
class ZoomedSceneExample(ZoomedScene):
CONFIG = {
"zoom_factor": 0.3,
"zoomed_display_height": 1,
"zoomed_display_width": 6,
"image_frame_stroke_width": 20,
"zoomed_camera_config": {
"default_frame_stroke_width": 3,
},
}
def construct(self):
# Set objects
dot = Dot().shift(UL*2)
a_line = Line((0,0,0),(1,1,0)).shift(UL*2) ## THIS IS THE ONLY CHANGE
self.add(a_line) ## TO THE EXAMPLE CODE
image=ImageMobject(np.uint8([[ 0, 100,30 , 200],
[255,0,5 , 33]]))
image.set_height(7)
frame_text=TextMobject("Frame",color=PURPLE).scale(1.4)
zoomed_camera_text=TextMobject("Zommed camera",color=RED).scale(1.4)
self.add(image,dot)
# Set camera
zoomed_camera = self.zoomed_camera
zoomed_display = self.zoomed_display
frame = zoomed_camera.frame
zoomed_display_frame = zoomed_display.display_frame
frame.move_to(dot)
frame.set_color(PURPLE)
zoomed_display_frame.set_color(RED)
zoomed_display.shift(DOWN)
# brackground zoomed_display
zd_rect = BackgroundRectangle(
zoomed_display,
fill_opacity=0,
buff=MED_SMALL_BUFF,
)
self.add_foreground_mobject(zd_rect)
# animation of unfold camera
unfold_camera = UpdateFromFunc(
zd_rect,
lambda rect: rect.replace(zoomed_display)
)
frame_text.next_to(frame,DOWN)
self.play(
ShowCreation(frame),
FadeInFromDown(frame_text)
)
# Activate zooming
self.activate_zooming()
self.play(
# You have to add this line
self.get_zoomed_display_pop_out_animation(),
unfold_camera
)
zoomed_camera_text.next_to(zoomed_display_frame,DOWN)
self.play(FadeInFromDown(zoomed_camera_text))
# Scale in x y z
scale_factor=[0.5,1.5,0]
# Resize the frame and zoomed camera
self.play(
frame.scale, scale_factor,
zoomed_display.scale, scale_factor,
FadeOut(zoomed_camera_text),
FadeOut(frame_text)
)
# Resize the frame
self.play(
frame.scale,3,
frame.shift,2.5*DOWN
)
# Resize zoomed camera
self.play(
ScaleInPlace(zoomed_display,2)
)
self.wait()
self.play(
self.get_zoomed_display_pop_out_animation(),
unfold_camera,
# -------> Inverse
rate_func=lambda t: smooth(1-t),
)
self.play(
Uncreate(zoomed_display_frame),
FadeOut(frame),
)
self.wait()
当我用 Manim 渲染它时,我发现缩放没有像我预期的那样工作。这是视频的屏幕截图:
不放大时,线条很粗。但在放大显示中,这条线显得明显更细。为什么是这样?我可以修复此效果,以便线宽随缩放正确缩放吗?
试试这个:
# Set camera
zoomed_camera = self.zoomed_camera
zoomed_camera.cairo_line_width_multiple = 0.1 # <-
厚度计算在this way。
这是一些示例代码的修改版本,来自 this page 的底部。唯一的变化是我添加了一行:
from manimlib.imports import *
class ZoomedSceneExample(ZoomedScene):
CONFIG = {
"zoom_factor": 0.3,
"zoomed_display_height": 1,
"zoomed_display_width": 6,
"image_frame_stroke_width": 20,
"zoomed_camera_config": {
"default_frame_stroke_width": 3,
},
}
def construct(self):
# Set objects
dot = Dot().shift(UL*2)
a_line = Line((0,0,0),(1,1,0)).shift(UL*2) ## THIS IS THE ONLY CHANGE
self.add(a_line) ## TO THE EXAMPLE CODE
image=ImageMobject(np.uint8([[ 0, 100,30 , 200],
[255,0,5 , 33]]))
image.set_height(7)
frame_text=TextMobject("Frame",color=PURPLE).scale(1.4)
zoomed_camera_text=TextMobject("Zommed camera",color=RED).scale(1.4)
self.add(image,dot)
# Set camera
zoomed_camera = self.zoomed_camera
zoomed_display = self.zoomed_display
frame = zoomed_camera.frame
zoomed_display_frame = zoomed_display.display_frame
frame.move_to(dot)
frame.set_color(PURPLE)
zoomed_display_frame.set_color(RED)
zoomed_display.shift(DOWN)
# brackground zoomed_display
zd_rect = BackgroundRectangle(
zoomed_display,
fill_opacity=0,
buff=MED_SMALL_BUFF,
)
self.add_foreground_mobject(zd_rect)
# animation of unfold camera
unfold_camera = UpdateFromFunc(
zd_rect,
lambda rect: rect.replace(zoomed_display)
)
frame_text.next_to(frame,DOWN)
self.play(
ShowCreation(frame),
FadeInFromDown(frame_text)
)
# Activate zooming
self.activate_zooming()
self.play(
# You have to add this line
self.get_zoomed_display_pop_out_animation(),
unfold_camera
)
zoomed_camera_text.next_to(zoomed_display_frame,DOWN)
self.play(FadeInFromDown(zoomed_camera_text))
# Scale in x y z
scale_factor=[0.5,1.5,0]
# Resize the frame and zoomed camera
self.play(
frame.scale, scale_factor,
zoomed_display.scale, scale_factor,
FadeOut(zoomed_camera_text),
FadeOut(frame_text)
)
# Resize the frame
self.play(
frame.scale,3,
frame.shift,2.5*DOWN
)
# Resize zoomed camera
self.play(
ScaleInPlace(zoomed_display,2)
)
self.wait()
self.play(
self.get_zoomed_display_pop_out_animation(),
unfold_camera,
# -------> Inverse
rate_func=lambda t: smooth(1-t),
)
self.play(
Uncreate(zoomed_display_frame),
FadeOut(frame),
)
self.wait()
当我用 Manim 渲染它时,我发现缩放没有像我预期的那样工作。这是视频的屏幕截图:
不放大时,线条很粗。但在放大显示中,这条线显得明显更细。为什么是这样?我可以修复此效果,以便线宽随缩放正确缩放吗?
试试这个:
# Set camera
zoomed_camera = self.zoomed_camera
zoomed_camera.cairo_line_width_multiple = 0.1 # <-
厚度计算在this way。