在下面的代码中,我以
条状物
. 每条带沿垂直轴移动一定量(类似于水波模拟,从
here
)但是,动画之后,图像
调光器
一定程度上。为什么会这样?
代码
window.onload = () => {
// Setup
const cvs = document.getElementById("cvs");
cvs.width = window.innerWidth;
cvs.height = window.innerHeight;
const c = cvs.getContext("2d");
c.fillStyle = "rgba(255, 255, 255, 1)";
let phase = 0, margin = 30;
// Flag Image
let flag = new Image();
flag.src = document.getElementById("India").src;
flag.onload = () => {
// c.drawImage(flag, margin, margin);
// Uncomment the above line and comment out the below line, if you want to see the original contrast.
setInterval(wave, 120);
}
// Animate function
let wave = () => {
c.fillRect(0, 0, cvs.width, cvs.height);
let wid = flag.width;
// Drawing flag in the form of slits
for(let i = 0; i < wid; i++) {
let y = margin + Math.sin(i/30 + phase) * 4;
c.drawImage(flag, i, 0, 1, flag.height, margin + i, y , 0.5, flag.height);
}
phase += 0.5;
}
};