canvas实现五角星辟出闪电动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas实现五角星辟出闪电动画效果代码

代码标签: canvas 五角星 辟出 闪电 动画

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

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

<head>
  <meta charset="UTF-8">
  

  
  
<style>
html,
body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  width: 100dvw;
  overflow: hidden;
  background: black;
  display: grid;
  place-items: center;
  position: relative;
}
</style>


  
  
</head>

<body translate="no">
  <canvas id="canvas"></canvas>
  
      <script  >
const ctx = canvas.getContext("2d");
const pointsCount = 500;
let centerX;
let centerY;
let levels = [];

let yStart = 10;
const levelsCount = 30;
let pos = [];

const a = (count, map) => new Array(count).fill(0).map(map);

const createPoints = () => {
  levels = a(levelsCount, (_, level) =>
  a(pointsCount, (_, index) => ({
    x: pos.x,
    y: pos.y + yStart * level * 0.5 })));


};
const createPos = () => {
  pos = a(levelsCount, (_, index) => ({ x: centerX, y: yStart * (index + 1) }));
};
const updateSize = () => {
  canvas.width = window.innerWidth;
  canvas.height = window.innerHeight;
  centerX = canvas.width / 2;
  centerY = canvas.height / 2;
  ctx.f.........完整代码请登录后点击上方下载按钮下载查看

网友评论0