import {makeScene2D, Rect, Node} from '@motion-canvas/2d';
import {all, sequence, waitFor} from '@motion-canvas/core';
export default makeScene2D(function* (view) {
// Create initial layout with 3 rectangles
const layout = new Rect({
layout: true,
padding: 20,
gap: 20,
direction: 'row',
children: [
new Rect({
width: 100,
height: 100,
fill: '#3498db',
}),
new Rect({
width: 100,
height: 100,
fill: '#2ecc71',
}),
new Rect({
width: 100,
height: 100,
fill: '#e74c3c',
}),
],
});
view.add(layout);
// Initial pause
yield* waitFor(1);
// Create new rectangle with initial scale of 0
const newRect = new Rect({
width: 100,
height: 100,
fill: '#9b59b6',
scale: 0,
});
// Add new rectangle to layout
layout.add(newRect);
// Animate the new rectangle appearing
yield* sequence(0.3,
newRect.scale(1, 0.5),
all(
// Optional: animate other properties
newRect.fill('#8e44ad', 0.3),
layout.position.x(-50, 0.3)
)
);
});