animation = {
const elem = html`<div>`;
elem.style.backgroundColor = "#ffe8b4";
const params = {
width: 500,
height: 500,
autostart: true
}
const two = new Two(params).appendTo(elem);
const numberOfShapes = 12;
const plotRadius = 150;
const shapes = [];
const fullRotation = Math.PI * 2;
for (let i = 0; i < numberOfShapes; i++) {
const angle = (fullRotation * i) / numberOfShapes;
const x = plotRadius * Math.cos(angle);
const y = plotRadius * Math.sin(angle);
const shape = two.makeRectangle(x, y, 50, 50);
shape.noStroke();
var gradLinA = two.makeLinearGradient(
-100,
50,
100,
-50,
new Two.Stop(0, "#f9bc31", 1),
new Two.Stop(1, "red", 1),
);
shape.fill = gradLinA;
shape.rotation = angle;
shapes.push(shape);
}
const group = two.makeGroup(shapes);
group.translation.set(250,250);
let scaler = 1;
let scaling = "grow";
two.bind('update', function() {
group.rotation += 0.005;
if (scaling === "grow"){
scaler += 0.005;
}
if (scaling === "shrink"){
scaler -= 0.005;
}
if (scaler > 3){
scaling = "shrink";
}
if (scaler <0.5){
scaling = "grow";
}
shapes.forEach(shape => {
shape.rotation += 0.025;
shape.scale = scaler;
})
})
return elem;
}