canvas实现彩色圈圈绘制动画效果代码

代码语言:html

所属分类:动画

代码描述:canvas实现彩色圈圈绘制动画效果代码

代码标签: canvas 彩色 圈圈 绘制 动画

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


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

<head>

  <meta charset="UTF-8">
  



</head>

<body>

  
      <script>
"use strict"; // Paul Slaymaker, paul25882@gmail.com
const body = document.getElementsByTagName("body").item(0);
body.style.background = "#000";
const TP = 2 * Math.PI;
const CSIZE = 400;

const ctx = (() => {
  let d = document.createElement("div");
  d.style.textAlign = "center";
  body.append(d);
  let c = document.createElement("canvas");
  c.width = 2 * CSIZE;
  c.height = 2 * CSIZE;
  d.append(c);
  return c.getContext("2d");
})();
ctx.translate(CSIZE, CSIZE);

onresize = () => {
  let D = Math.min(window.innerWidth, window.innerHeight) - 40;
  ctx.canvas.style.width = ctx.canvas.style.height = D + "px";
};

const getRandomInt = (min, max, low) => {
  if (low) {
    return Math.floor(Math.random() * Math.random() * (max - min)) + min;
  } else {
    return Math.floor(Math.random() * (max - min)) + min;
  }
};

var colors = [];
var hues = [];
var setColors = () => {
  let colorCount = 3;
  let h = getRandomInt(180, 270);
  for (let i = 0; i < colorCount; i++) {
    let hd = Math.round(180 / colorCount) * i + getRandomInt(-10, 10);
    let hue = (h + hd) % 360;
    hues.splice(getRandomInt(0, hues.length + 1), 0, hue);
  }
  for (let i = 0; i < colorCount; i++) colors[i] = "hsl(" + hues[i] + ",98%,50%)";
};
setColors();

const dm1 = new DOMMatrix([-1, 0, 0, 1, 0, 0]);
const dm2 = new DOMMatrix([1, 0, 0, -1, 0, 0]);

var Brush = function (idx) {
  this.col = idx;
  this.t = getRandomInt(0, 800);
  this.CT = getRandomInt(800, 100.........完整代码请登录后点击上方下载按钮下载查看

网友评论0