canvas实现秋天没树叶的树干摆动动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas实现秋天没树叶的树干摆动动画效果代码

代码标签: canvas 秋天 树叶 树干 摆动 动画

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

<!DOCTYPE html>
<html lang="en">

<head>

    <meta charset="UTF-8">



</head>

<body>



    <script>
        console.clear();
        
        const canvas = document.createElement('canvas');
        canvas.style.display = 'block';
        document.body.style.margin = '0';
        document.body.appendChild(canvas);
        let w, h;
        const ctx = canvas.getContext('2d');
        
        requestAnimationFrame(render);
        
        let global = { frame: 0, t: 0, a: 0, wind: 0, windTarget: 0 };
        
        function render() {
          [w, h] = [innerWidth, innerHeight];
          [canvas.width, canvas.height] = [w, h];
          ctx.lineWidth = 1.5;
          ctx.fillRect(0, 0, w, h);
          ctx.strokeStyle = '#ffffff';
        
          // global.a = Math.abs(((global.t / 8) % 1) * 2 - 1) * Math.PI / 8 - Math.PI / 16;
          if (global.frame % 120 === 0) global.windTarget = Math.random() * 16;
          const ratio = 0.999;
          global.wind =.........完整代码请登录后点击上方下载按钮下载查看

网友评论0