Spline
Click to preview animation
import {makeScene2D, Spline, Knot} from '@motion-canvas/2d';
import {createRef} from '@motion-canvas/core';
export default makeScene2D(function* (view) {
const spline = createRef<Spline>();
view.add(
<Spline ref={spline} lineWidth={4} fill={'#e13238'} closed>
<Knot position={[-120, -30]} startHandle={[0, 70]} />
<Knot
position={[0, -50]}
startHandle={[-40, -60]}
endHandle={[40, -60]}
/>
<Knot position={[120, -30]} startHandle={[0, -70]} />
<Knot position={[0, 100]} startHandle={[5, 0]} />
</Spline>,
);
yield* spline().scale(0.9, 0.6).to(1, 0.4);
});
Spline 组件允许我们通过一系列控制点绘制和动画平滑曲线。
如果您只想绘制一条简单的贝塞尔曲线,请查看贝塞尔曲线组件。
定义控制点
为了绘制样条曲线,我们需要指定它的节点是什么。Spline 组件提供了多种指定这些控制点的方法,我们将在本节中介绍这些方法。