如何用JavaScript制作背景动画波浪?

How to make background animation wave with JavaScript?

我想做一个像这个网站英雄栏目的背景动画波浪。 https://raze.network/

谁能帮我做这个动画背景波?

谢谢:)

codepen 上有一个很好的示例,您可以使用它来大致了解如何使用 JavaScript 为这个波浪制作动画。作者允许在 CodePen 上发表评论,所以我会与他取得联系。


let noise = new SimplexNoise();

function draw(e) {
    let xCount = 35;
    let yCount = 80;
    let iXCount = 1 / (xCount - 1);
    let iYCount = 1 / (yCount - 1);
    let time = e * 0.001;
    let timeStep = 0.01;
    let grad = ctx.createLinearGradient(-width, 0, width, height);
    let t = time % 1;
    let tSide = floor(time % 2) === 0;
    let hueA = tSide ? 340 : 210;
    let hueB = !tSide ? 340 : 210;
    let colorA = hsl(hueA, 100, 50);
    let colorB = hsl(hueB, 100, 50);
    grad.addColorStop(map(t, 0, 1, THIRD, ZERO), colorA);
    grad.addColorStop(map(t, 0, 1, TWO_THIRDS, THIRD), colorB);
    grad.addColorStop(map(t, 0, 1, ONE, TWO_THIRDS), colorA);
    ctx.globalAlpha = map(cos(time), -1, 1, 0.15, 0.3);
    background(grad);
    ctx.globalAlpha = 1;
    beginPath();
    for(let j = 0; j < yCount; j++) {
        let tj = j * iYCount;
        let c = cos(tj * TAU + time) * 0.1;
        for(let i = 0; i < xCount; i++) {
            let t = i * iXCount;
            let n = noise.noise3D(t, time, c);
            let y = n * height_half;
            let x = t * (width + 20) - width_half - 10;
            (i ? lineTo : moveTo)(x, y);
        }
        time += timeStep;
    }
    compositeOperation(compOper.lighter);
    ctx.filter = 'blur(10px)';
    stroke(grad, 5);
    ctx.filter = 'blur(5px)';
    stroke(hsl(0, 0, 100, 0.8), 2);
}

https://codepen.io/Alca/pen/gzxXLq