js实现canvas风扇叶背景效果代码

代码语言:html

所属分类:背景

代码描述:js实现canvas风扇叶背景效果代码

代码标签: 风扇 叶背景 ( 背景 ) 效果

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

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

<head>

    <meta charset="UTF-8">



    <style>
        body, html {
          margin: 0;
          overflow: hidden;
        }
        
        canvas {
          display: block;
          cursor: pointer;
        }
    </style>


</head>

<body>
    <canvas id="canvas"></canvas>



    <script>
        /*
      Johan Karlsson, 2021
      https://twitter.com/DonKarlssonSan
      MIT License, see Details View
    */
    
    let canvas;
    let ctx;
    let w, h;
    
    function setup() {
      canvas = document.querySelector("#canvas");
      ctx = canvas.getContext("2d");
      resize();
      window.addEventListener("resize", () => {
        resize();
        draw();
      });
      canvas.addEventListener("click", draw);
    }
    
    function resize() {
      w = canvas.width = window.innerWidth;
      h = canvas.height = window.innerHeight;
    }
    
    function drawOutside(r) {
      ctx.lineWidth = r * 0.1;
      ctx.strokeStyle = "black";
      ctx.beginPath();
      ctx.arc(0, 0, r, 0, Math.PI, true);
      ctx.arc(-r, r, r, Math.PI / 2 * 3, 0, false);
      ctx.arc(r, r, r, Math.PI, Math.PI / 2 * 3, false);
      ctx.stroke();
    }
    
    function drawCircles(x, y, r, angle) {.........完整代码请登录后点击上方下载按钮下载查看

网友评论0