圆角三角形背景效果

代码语言:html

所属分类:背景

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

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

<style>
body {
  font-family: Arial, Helvetica, "Liberation Sans", FreeSans, sans-serif;
  background-color: #000;
  margin:0;
  padding:0;
  border-width:0;
}
</style>

</head>
<body translate="no">

<script >
"use strict";

window.addEventListener("load", function () {

  /* constants to play with */
  const limBiTri = 150;
  const dHue = 40;
  const halfMargin = 3; // px for space between triangles
  const roundRadius = 10;
  /*  halfMargin and roundRadius should be kept positive and small with respect to limBiTri
                            or insconsistency issues may arise */

  /* modifications beyond this line at your own risks */

  let canv, ctx; // canvas and context : global variables (I know :( )
  let maxx, maxy; // canvas sizes (in pixels)
  let hueMono;
  let monochrome;
  let bt0, bt1, bt2;

  let prevTri, currTri;

  // shortcuts for Math.…

  const mrandom = Math.random;
  const mhypot = Math.hypot;
  const matan2 = Math.atan2;
  const mabs = Math.abs;

  //-----------------------------------------------------------------------------
  // miscellaneous functions
  //-----------------------------------------------------------------------------
  function alea(min, max) {
    // random number [min..max[ . If no max is provided, [0..min[

    if (typeof max == 'undefined') return min * mrandom();
    return min + (max - min) * mrandom();
  } // alea

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  function isPositiveRot(p0, p1, p2) {

    // returns true if turn positively going from p0 to p1 to p2
    let dx0 = p1[0] - p0[0];
    let dy0 = p1[1] - p0[1];
    let dx1 = p2[0] - p1[0];
    let dy1 = p2[1] - p1[1];

    return dx0 * dy1 - dx1 * dy0 >= 0;

  } // isPositiveRot

  // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

  function projection(p0, p1, p) {
    // returns projection of p on (p0, p1)

    let [x0, y0] = p0;
    let [x1, y1] = p1;
    let [x, y] = p;

    let dx = x1 - x0;
    let dy = y1 - y0;

    let xproj, yproj;
.........完整代码请登录后点击上方下载按钮下载查看

网友评论0