simplex-noise实现canvas多触脚不明生物跟随鼠标运动动画效果代码

代码语言:html

所属分类:动画

代码描述:simplex-noise实现canvas多触脚不明生物跟随鼠标运动动画效果代码

代码标签: simplex-noise canvas 触脚 生物 跟随 鼠标 运动

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

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

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

    <style>
        html, body {
      overflow: hidden;
      background: black;
      cursor: crosshair;
    }
    
    .controls {
      bottom: 0;
      display: flex;
      opacity: 0.8;
      padding: 16px;
      position: fixed;
      right: 0;
      z-index: 2;
    }
    .controls__label {
      border: 1px solid #6a1b9a;
      cursor: pointer;
      display: block;
      height: 36px;
      margin-left: 16px;
      padding: 0 16px;
      border-radius: 17px;
    }
    .controls__rdo {
      display: none;
    }
    .controls__rdo:checked + .controls__label {
      background-color: #6a1b9a;
    }
    .controls__icon {
      align-items: center;
      display: block;
    }
    .controls__icon--line, .controls__icon--dot-line {
      position: relative;
      top: calc(50% - 1px);
    }
    .controls__icon--dot {
      position: relative;
      transform: translateY(calc(50% + 1px));
    }
    .controls__icon--line, .controls__icon--dot-line {
      background-color: white;
      height: 1px;
      width: 16px;
    }
    .controls__icon--dot-line {
      position: relative;
    }
    .controls__icon--dot-line:after {
      content: "";
      display: block;
      position: absolute;
      transform: translateY(calc(-50% + 1px));
    }
    .controls__icon--dot, .controls__icon--dot-line:after {
      border: 1px solid white;
      border-radius: 50%;
      height: 14px;
      width: 14px;
    }
    </style>
</head>

<body>
    <!-- partial:index.partial.html -->
    <div class="controls">
        <input type="radio" class="controls__rdo" name="style" id="rdo-dot-line" value="dot-line" checked />
        <label class="controls__label" for="rdo-dot-line">
		<span class="controls__icon controls__icon--dot-line"></span>
	</label>
        <input type="radio" class="controls__rdo" name="style" id="rdo-dot" value="dot" />
        <label class="controls__label" for="rdo-dot">
		<span class="controls__icon controls__icon--dot"></span>
	</label>
        <input type="radio" class="controls__rdo" name="style" id="rdo-line" value="line" />
        <label class="controls__label" for="rdo-line">
		<span class="controls__icon controls__icon--line"></span>
	</label>
    </div>
    <!-- partial -->
    <script>
        "use strict";
    
    const {
      abs,
      acos,
      asin,
      atan,
      atan2,
      ceil,
      cos,
      max,
      min,
      PI,
      pow,
      random,
      round,
      sin,
      sqrt,
      tan } =
    Math;
    const HALF_PI = 0.5 * PI;
    const QUART_PI = 0.25 * PI;
    const TAU = 2 * PI;
    const TO_RAD = PI / 180;
    const G = 6.67 * pow(10, -11);
    const EPSILON = 2.220446049250313e-16;
    const rand = n => n * random();
    const randIn = (_min, _max) => rand(_max - _min) + _min;
    const randRange = n => n - rand(2 * n);
    const fadeIn = (t, m) => t / m;
    const fadeOut = (t, m) => (m - t) / m;
    const fadeInOut = (t, m) => {
      let hm = 0.5 * m;
      return abs((t + hm) % m - hm) / hm;
    };
    const dist = (x1, y1, x2, y2) => sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    const angle = (x1, y1, x2, y2) => atan2(y2 - y1, x2 - x1);
    const lerp = (a, b, t) => (1 - t) * a + t * b;
    const clamp = (n, _min, _max) => min(max(n, _min), _max);
    const norm = (n, _min, _max) => (n - _min) / (_max - _min);
    const floor = n => n | 0;
    const fract = n => n - floor(n);
    const vh = p => p * window.innerHeight * 0.01;
    const vw = p => p * window.innerWidth * 0.01;
    const vmin = p => min(vh(p), vw(p));
    const vmax = p => max(vh(p), vw(p));
    const intToRGBA = n => {
      let r, g, b, a;
    
      n >>>= 0;
    
      r = (n & 0xff000000) >>> 24;
      g = (n & 0xff0000) >>> 16;
      b = (n & 0xff00) >>> 8;
      a = (n & 0xff) / 255;
    
      return `rgba(${[r, g, b, a].join()})`;
    };
    const nearestMultiple = (n, d) => n - n % d;
    const drawTypes = {
      FILL: "fill",
      STROKE: "stroke" };
    
    const textAlignTypes = {
      CENTER: "center",
      END: "end",
      LEFT: "left",
      RIGHT: "right",
      START: "start" };
    
    const textBaselineTypes = {
      ALPHABETIC: "alphabetic",
      BOTTOM: "bottom",
      HANGING: "hanging",
      MIDDLE: "middle",
      TOP: "top" };
    
    const debounce = (fn, wait = 200) => {
      let timeout;
    .........完整代码请登录后点击上方下载按钮下载查看

网友评论0