js canvas webgl实现三维十二面体粒子效果代码

代码语言:html

所属分类:粒子

代码描述:js canvas webgl实现三维十二面体粒子效果代码

代码标签: 实现 三维 十二 面体 粒子 效果

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

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

<head>

  <meta charset="UTF-8">

  



</head>

<body>

      <script>
Object.assign(window, {
  random: Math.random,
  sin: Math.sin });


Object.assign(window, {
  ech(a, b, f) {a.forEach((e, i) => a[i] = f(e, b[i]));},
  add(a, b) {ech(a, b, (x, y) => x + y);},
  sub(a, b) {ech(a, b, (x, y) => x - y);},
  mult(a, s) {ech(a, a, x => x * s);},
  mag(p) {return Math.hypot(...p);},
  norm(a) {mult(a, 1 / mag(a));},
  g: 0.5 + Math.sqrt(5) / 2 });


function shuffle(array) {
  for (let i = array.length - 1; i > 0; i--) {
    const j = random() * (i + 1) | 0;
    [array[i], array[j]] = [array[j], array[i]];
  }
}

const count = 1e5;

const dodec = [
(m, n) => [-1, m, n],
(m, n) => [1, m, n],
(m, n) => [0, m * g, n / g],
(m, n) => [m * g, n / g, 0],
(m, n) => [n / g, 0, m * g]];


const d = [...Array(20)].map((e, i) => {
  const m = i / 5 | 0;
  return dodec[i % 5](m % 2 * 2 - 1, (m / 2 | 0) * 2 - 1);
});

let f = (x, i) => x + r.........完整代码请登录后点击上方下载按钮下载查看

网友评论0