03 · path / 曲线 / 椭圆 / 多边形

画自由形状 —— 用 SVG path 语法,但渲染是手绘的

path(SVG path 命令)

svg.appendChild(rc.path('M 10 80 C 40 10, 65 10, 95 80 S 150 150, 180 80'));

curve(简化的贝塞尔)

svg.appendChild(rc.curve([[10,80],[60,10],[110,80],[160,10],[210,80]]));

ellipse(椭圆)

svg.appendChild(rc.ellipse(130, 60, 200, 80)); ← cx,cy,width,height

polygon(多边形)

svg.appendChild(rc.polygon([[20,100],[80,20],[140,100],[200,20]]));

arc(圆弧)

svg.appendChild(rc.arc(130, 60, 80, 80, Math.PI, Math.PI * 1.8));

linearPath(折线)

svg.appendChild(rc.linearPath([[10,30],[80,90],[150,30],[220,90]]));

path() 是最自由的方法:你直接传 SVG path 的 d 字符串 (M/L/C/Q/Z 等命令),RoughJS 会把每段加抖动。
例:'M 10 80 Q 95 10 180 80 T 350 80'(Q 是二次贝塞尔,T 是平滑镜像)

curve() 是 path() 的简化版:传一组点,自动连成平滑贝塞尔。 控制点不够灵活但写起来短。

polygon() 收尾自动闭合linearPath() 不闭合。