噪点波纹动画效果

代码语言:html

所属分类:动画

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">

    <style>
        html,
        body {
            margin: 0;
            padding: 0;
        }

        body {
            overflow: hidden;
            width: 100vw;
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
            touch-action: none;
        }
    </style>

</head>
<body translate="no">
    <canvas class="js-canvas"></canvas>

    <script type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/simplex-noise.min.js"></script>
    <script>
        const simplex = new SimplexNoise();

        const distanceBetween = (vec1, vec2) => Math.hypot(vec2.x - vec1.x, vec2.y - vec1.y);
        const angleBetween = (vec1, vec2) => Math.atan2(vec2.y - vec1.y, vec2.x - vec1.x);
        const clamp = (value, min, max) => Math.max(min, Math.min(value, max));

        const canvas = document.querySelector('.js-canvas');
        const ctx = canvas.getContext('2d');

        const TAU = Math.PI * 2;

        const padding = 100;
        const width = window.innerWidth;
        const height = window.innerHeight;

        const midX = width >> 1;
        const midY = height >> 1;

        canvas.width = width;
        canvas.height = height;

        let phase = 0;
        const phaseSpeedMin = 0.009;
        const phaseSpeedMax = 0.02;
        let phaseSpeed = phaseSpeedMin;

        const pointer = {
            x: 0,
            y: 0
        };
        const position = {
            x: midX,
            y: midY
        };
        let velocity = 0;

        const numCircles = 20;
        const radius = 10;
        const radiusMax = 200;
        const radiusDecrease = (radiusMax - radius) / numCircles;

        const drawForm = ctx => {
            const force = 1 - Math.hypot(position.x - pointer.x, position.y - pointer.y) / Math.hypot(midX, midY);
            velocity += (force * 2 - velocity) / 2;

            const anglePointer = angleBetween(pointer, position);

            position.x += Math.cos(anglePointer) * velocity;
            position.y += Math.sin(anglePointer) * velocity;

          .........完整代码请登录后点击上方下载按钮下载查看

网友评论0