clip

class janim.items.effect.clip.Cmpt_FrameClip(*args, **kwargs)

基类:Component, Generic

copy() Self
become(other: Cmpt_FrameClip) Self
not_changed(other: Cmpt_FrameClip) bool
classmethod align_for_interpolate(cmpt1: Cmpt_FrameClip, cmpt2: Cmpt_FrameClip)
interpolate(cmpt1: Self, cmpt2: Self, alpha: float, *, path_func=None) None
set(left: float | None = None, top: float | None = None, right: float | None = None, bottom: float | None = None) Self
class janim.items.effect.clip.FrameClip(*items: Item, clip: tuple[float, float, float, float] = (0, 0, 0, 0), debug: bool = False, root_only: bool = False, **kwargs)

基类:FrameEffect

一个用于创建简单矩形裁剪效果的类

参数:
  • clip -- 裁剪区域的四个边界,分别是左、上、右、下,范围是 0~1 表示百分比

  • debug -- 是否开启调试模式,开启后裁剪区域外的部分会显示为半透明红色

clip
dynamic_uniforms()
create_border_rect(**kwargs) Rect

得到裁剪后的显示区域的包围矩形

class janim.items.effect.clip.Cmpt_Attrs(*args, **kwargs)

基类:Component, Generic

Cmpt_TransformableFrameClipCmpt_RectClipTransform 的基类

size: int = 1
copy() Self
become(other: Cmpt_TransformableFrameClip) Self
not_changed(other: Cmpt_TransformableFrameClip) bool
classmethod align_for_interpolate(cmpt1: Cmpt_TransformableFrameClip, cmpt2: Cmpt_TransformableFrameClip)
interpolate(cmpt1: Self, cmpt2: Self, alpha: float, *, path_func=None) None
class janim.items.effect.clip.Cmpt_TransformableFrameClip(*args, **kwargs)

基类:Cmpt_Attrs, Generic

size: int = 9
set(left: float | None = None, top: float | None = None, right: float | None = None, bottom: float | None = None, x_offset: float | None = None, y_offset: float | None = None, x_scale: float | None = None, y_scale: float | None = None, rotate: float | None = None, *, scale: float | None = None) Self
class janim.items.effect.clip.TransformableFrameClip(*items: Item, clip: tuple[float, float, float, float] = (0, 0, 0, 0), offset: tuple[float, float] = (0, 0), scale: tuple[float, float] | float = (1, 1), rotate: float = 0, debug: bool = False, root_only: bool = False, **kwargs)

基类:FrameEffect

FrameClip 类似,但支持更多的变换操作(偏移、缩放、旋转)

参数:
  • clip -- 裁剪区域的四个边界,分别是左、上、右、下,范围是 0~1 表示百分比

  • offset -- 裁剪区域 x 与 y 方向的的偏移量,单位是百分比

  • scale -- 裁剪区域 x 与 y 方向的缩放量,单位是百分比

  • rotate -- 裁剪区域的旋转角度

  • debug -- 是否开启调试模式,开启后裁剪区域外的部分会显示为半透明红色

可另行参考 RectClip,它在一些情况下会好用得多

clip
dynamic_uniforms()
create_border_rect(**kwargs) Rect

得到裁剪后的显示区域的包围矩形

class janim.items.effect.clip.Cmpt_RectClipTransform(*args, **kwargs)

基类:Cmpt_Attrs, Generic

size: int = 2
set(scale: float | None = None, rotate: float | None = None) Self
class janim.items.effect.clip.RectClip(*args, **kwargs)

基类:FrameEffect, FrameRect

矩形裁剪效果

FrameClip 不同,裁剪区域由当前 FrameRect 的几何形状动态决定,跟随该矩形的几何状态

参数:
  • *items -- 需要应用该裁剪效果的物件

  • anchor -- 裁剪内容变换时的锚点(场景坐标)

  • center_on --

    是否让锚点始终居中于矩形中心;

    默认为 False,则锚点位置相对于矩形边框的百分比始终不变;若为 True,则内容整体会被平移使得锚点处于矩形中心

  • scale -- 裁剪内容相对于锚点位置的缩放系数

  • rotate -- 裁剪内容相对于锚点位置的旋转角度(弧度制)

  • border -- 是否绘制裁剪矩形边框

其中:

  • anchor 也可以使用 set_anchor() 设置

  • center_on 也可以使用 set_center_on() 设置

  • scalerotate 也可以使用 .transform.set(...) 设置

小技巧

RectClip 几乎可以像一个 Rect 一样操作,进行各种变换与对齐,这使得将其放到合适的位置变得更加容易

并且在 border=True 时,Rect 的各种视觉特性,例如边框颜色,泛光效果等,都是可用的

RectClipExample
from janim.imports import *

class RectClipExample(Timeline):
    def construct(self):
        ANCHOR = LEFT * 2

        plane = NumberPlane(faded_line_ratio=1)
        dot = Dot(ANCHOR)
        txt = Text('Anchor')
        txt.points.next_to(dot, UP, buff=SMALL_BUFF)

        rect = RectClip(plane, dot, txt, anchor=ANCHOR, border=True)
        self.show(plane, dot, txt, rect)

        self.forward()
        self.play(
            rect.anim.points.scale([0.3, 0.5, 1]),
            rect.anim.points.shift(LEFT * 2),
            rect.anim.points.shift(UR),

            rect.anim.transform.set(scale=1.5, rotate=20 * DEGREES),
            Wait(0.5),
            rect.anim.transform.set(scale=1, rotate=0),

            rect.anim.set_center_on().color.set(RED),

            rect.anim.transform.set(scale=1.5, rotate=20 * DEGREES),
            Wait(0.5),
            rect.anim.transform.set(scale=1, rotate=0),

            lag_ratio=1,
        )
        self.forward()
class RCRenderer

基类:Renderer

render(item: RectClip) None
renderer_cls

RCRenderer 的别名

transform
set_anchor(point: Vect) Self
get_anchor() ndarray
set_center_on(center_on: bool = True) Self
is_center_on() bool
dynamic_uniforms()