document.body.innerHTML += `
<canvas id="c" width="600" height="600" />
<img src="https://picsum.photos/id/742/600/600"
style="display:none" onload="init(this)" crossorigin>
`;
function init(img) {
let ctx = c.getContext("2d");
ctx.drawImage(img, 0, 0);
let dx = 10;
let count = 180;
let s = c.width;
let step = s/(count + 1);
let d = ctx.getImageData(0, 0, s, s);
requestAnimationFrame(redraw);
function redraw(t){
ctx.clearRect(0, 0, s, s);
for (let i = 0; i < count; i++) {
let y = i*step+step/2;
y += Math.sin(y/40+t/700)*2
ctx.beginPath();
for (let x = 0; x < s; x++) {
let o = s*(y|0) + x|0;
ctx[x?'lineTo':'moveTo'](x, y - d.data[o*4]/40);
}
ctx.stroke();
}
requestAnimationFrame(redraw);
}
}
可以显示类似这样的内容:
这里是最好的解决方案!=)
特别是对你)