From box to pill
Animate a rectangle's dimensions and corner radius while its outline follows the same contour
Rect.cornerRadius rounds all four corners in local scene units. It defaults
to 0, so existing rectangles keep their sharp corners. Use Motion.tween
or Motion.tweenTo to animate it alongside width and height.
import * as Color from "effect-motion/Color";import * as Entity from "effect-motion/Entity";import * as Motion from "effect-motion/Motion";import * as Scene from "effect-motion/Scene";export const scene = Scene.make( "From box to pill", function* () { yield* Scene.instantiate("Text", { text: "FROM BOX TO PILL", position: Entity.vec3({ y: 170 }), textAnchor: "middle", fontSize: 30, fillColor: Color.hex("#e4edf8"), }); yield* Scene.instantiate("Text", { text: "One Rect. Animate width and cornerRadius together.", position: Entity.vec3({ y: 125 }), textAnchor: "middle", fontSize: 18, fillColor: Color.hex("#93a4bb"), }); const box = yield* Scene.instantiate("Rect", { width: 150, height: 150, fillColor: Color.hex("#246b69"), strokeColor: Color.rgba(115, 255, 215, 0.65), strokeWidth: 6, }); const outline = yield* Scene.instantiate("Rect", { position: Entity.vec3({ y: -150 }), width: 150, height: 40, fillColor: Color.transparent, strokeColor: Color.hex("#f8c773"), strokeWidth: 4, strokeDasharray: [16, 10], trimEnd: 0.75, }); yield* Motion.wait("1 second"); yield* Scene.all([ Motion.tweenTo( box, { width: 380, height: 110, cornerRadius: 55 }, "3 seconds", "easeInOutCubic", ), outline.pipe( Motion.tweenTo( { width: 380, cornerRadius: 20, trimOffset: 1, strokeDashoffset: -52, }, "3 seconds", "linear", ), ), ]); yield* Motion.wait("1 second"); }, { width: 800, height: 480, backgroundColor: Color.hex("#111c2e") },);The filled box becomes a pill between 1 and 4 seconds. Below it, a dashed outline rounds while its trim window and dash offset move around the contour. The translucent mint border keeps one opacity application across its joins.
The rendered radius is clamped to
[0, min(abs(width), abs(height)) / 2]. A negative radius draws sharp
corners. An oversized radius draws a pill, or a circle when both dimensions
have equal magnitude. The stored radius is unchanged: tweens still finish
on the exact authored target, including overshoots.
Dimensions keep their existing meaning. Negative widths or heights reflect
the local contour, and zero dimensions collapse it. Rounding happens before
scale, so a nonuniform scale stretches the corners along with the shape.
Position, rotation, and depth move the fill and outline together about the
rectangle's center.
For positive dimensions, the outline starts at the top-left corner's tangent on the top edge and travels clockwise. At radius zero it starts at the top-left corner. Trim and dash distances follow that local contour; reflected dimensions reflect the traversal too. The fill always stays complete. See Path and stroke controls for the shared trim and dash rules.