simpleAnimationCanvas = {
const width = 1200
const height = 300
const c = DOM.context2d(width, height);
const dataStart = _.range(0, 200).map(i => ({
id: i,
x: Math.random()*width,
y: Math.random()*height,
r: Math.random()*30,
fill: `rgb(${Math.round(Math.random()*255)}, ${Math.round(Math.random()*255)}, ${Math.round(Math.random()*255)})`
}))
const dataEnd = _.range(0, 200).map(i => ({
id: i,
x: Math.random()*width,
y: Math.random()*height,
r: Math.random()*20,
fill: `rgb(${Math.round(Math.random()*255)}, ${Math.round(Math.random()*255)}, ${Math.round(Math.random()*255)})`
}))
const draw = (data) => {
c.fillStyle = "black"
c.fillRect(0, 0, width, height);
for (const { x, y, r, fill } of data) {
c.beginPath();
c.arc(x, y, r, 0, 2*Math.PI)
c.fillStyle = fill
c.fill()
}
}
const tl = gsap.to(dataStart, {
x: (index) => dataEnd[index].x,
y: (index) => dataEnd[index].y,
r: (index) => dataEnd[index].r,
fill: (index) => dataEnd[index].fill,
duration: 3,
ease: 'bounce',
onUpdate: () => draw(dataStart)
})
tl.pause()
const play = document.querySelector("#play-test");
const pause = document.querySelector("#pause-test");
const restart = document.querySelector("#restart-test");
const reverse = document.querySelector("#reverse-test");
play.onclick = () => tl.play();
restart.onclick = () => tl.restart()
pause.onclick = () => tl.pause();
reverse.onclick = () => tl.reverse();
draw(dataStart)
yield c.canvas;
}