canvas实现皮带螺旋线条效果代码

代码语言:html

所属分类:布局界面

代码描述:canvas实现皮带螺旋线条效果代码,点击可重新绘制。

代码标签: canvas 皮带 螺旋 线条

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


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

<head>

  <meta charset="UTF-8">
  

  
  
  
<style>
body, html {
  margin: 0;
  background-color: black;
  overflow: hidden;
}

canvas {
  display: block;
  cursor: pointer;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
</style>



</head>

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

      <script>

/*
  Johan Karlsson, 2022
  https://twitter.com/DonKarlssonSan
  MIT License, see Details View
*/
let canvas;
let ctx;
let w, h;
let stepSize;

function setup() {
  canvas = document.querySelector("#canvas");
  ctx = canvas.getContext("2d");
  resize();
  window.addEventListener("resize", () => {
    resize();
    draw();
  });
  canvas.addEventListener("click", draw);
}

function resize() {
  const m = Math.min(window.innerWidth, window.innerHeight); 
  w = canvas.width = m;
  h = canvas.height = m;
}

function draw() {
  stepSize = Math.random() * 2 + 0.5;
  ctx.fillStyle = "black";
  ctx.fillRect(0, 0, w, h);
 
  ctx.lineWidth = w * 0.0015;
  ctx.strokeStyle = "#ffffff04";
  let mx = w .........完整代码请登录后点击上方下载按钮下载查看

网友评论0