const images = [
{
src: 'https://i.imgur.com/GigS3KR.png',
translate: [ 50, 50, 500, 20 ],
rotate: [ 340, 200 ],
draw: [ 0, 0, 0.95 ],
},
{
src: 'https://i.imgur.com/y3JAe69.png',
translate: [ 5, 0, 382, 2 ],
rotate: [ 630, 40 ],
draw: [ 150, 100, 0.84 ],
},
{
src: 'https://i.imgur.com/v30JIWp.png',
translate: [ 8, 150, 198, 3 ],
rotate: [ 500, 450 ],
draw: [ 0, 0, 0.7 ],
},
].map(n => {
n.draw.unshift(new Image);
n.draw[0].src = n.src;
return n;
});
const canvases = document.querySelectorAll('.canvas');
const canvasSize = document.documentElement.clientWidth;
for (const n of canvases) {
n.setAttribute('width', canvasSize);
n.setAttribute('height', canvasSize);
}
let ts0;
window.requestAnimationFrame(function draw(ts) {
for (const n of canvases) {
ts0 = ts0 || ts;
const dt = ts - ts0;
const ctx = n.getContext('2d');
ctx.clearRect(0, 0, canvasSize, canvasSize);
for (const { translate: t, rotate: r, draw: d } of images) {
ctx.save();
ctx.translate(t[0], t[1] + Math.sin(dt / t[2]) / t[3]);
ctx.rotate(Math.sin(dt / r[0]) / r[1]);
ctx.drawImage(d[0], d[1], d[2], canvasSize * d[3], canvasSize * d[3]);
ctx.restore();
}
}
window.requestAnimationFrame(draw);
});