97国产精品视频人人做人人爱,3344在线观看无码,成年人国产视频,欧美日一级片,在线看AV天堂,高清无码一本到东京热,欧美一级黄片一区2区,免费又爽又刺激高潮网址

canvas粒子效果

2018-7-27    seo達人

如果您想訂閱本博客內容,每天自動發到您的郵箱中, 請點這里

<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    html, body {
      margin: 0;
      padding: 0;
      height: 100%;
      overflow: hidden;
    }
    .container {
      width: 100%;
      height: 100%;
    }
  </style>
</head>
<body>
  <div class="container">
    <canvas id="cs"></canvas>
  </div>
</body>
<script>
  function MoveBalls(element, opts) {
    var canvas = document.querySelector(element);
    this.canvas = canvas;
    this.ctx = canvas.getContext("2d");
    var defaultOpts = {
      total: 100,
      color: "#00D0FF",
      size: 1,
      width: this.canvas.parentNode.clientWidth,
      height: this.canvas.parentNode.clientHeight
    };
    var opts = opts || defaultOpts;
    for (var key in opts) {
        defaultOpts[key] = opts[key];
    };
    for (var key in defaultOpts) {
        this[key] = defaultOpts[key];
    };
    opts = null;
    defaultOpts = null;
    // 鼠標坐標
    this.coordinate = {
      x: null,
      y: null,
      max: 100
    };
    // 粒子
    this.dots = [];
    // 含鼠標坐標的粒子數組
    this.newDots = [];
    // 總數
    this.count = 0;
    // requestAnimationFrame兼容處理
    window.requestAnimationFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(callback) {
          window.setTimeout(callback, 1000 / 60);
        };
    this.colorReg = /[rgba()]/g;
    this.init();
  };
  MoveBalls.prototype = {
    constructor: MoveBalls,
    init: function () {
      var _this = this;
      this.freshResize();
      this.mouseEvent();
      this.getDots();
      var timer = setTimeout(function () {
        clearTimeout(timer);
        _this.draw(_this)
      }, 300);
    },
    colorCheck: function () {
      this.canvas.style.color = this.color;
      var colorData = this.canvas.style.color;
      return colorData = colorData.replace(this.colorReg, "").split(",");
    },
    resize: function (self) {
      var _this = self || this;
      _this.canvas.width = _this.width;
      _this.canvas.height = _this.height;
    },
    freshResize: function () {
      this.resize();
      var _this = this;
      window.addEventListener("resize", function () {
        _this.resize(_this);
      });
    },
    mouseEvent: function () {
      var _this = this;
      _this.canvas.addEventListener("mousemove", function (e) {
        var e = e || winodw.event;
        _this.coordinate.x = e.offsetX ? e.offsetX : e.layerX;
        _this.coordinate.y = e.offsetY ? e.offsetY : e.layerY;
      });
      _this.canvas.addEventListener("mouseout", function () {
        _this.coordinate.x = null;
        _this.coordinate.y = null;
      })
    },
    getDots: function () {
      while(this.count < this.total) {
        var x = Math.random() * this.canvas.width;
        var y = Math.random() * this.canvas.height;
        var xMove = Math.random() * 2 - 1;
        var yMove = Math.random() * 2 - 1;
        this.dots.push({
          x: x,
          y: y,
          xMove: xMove,
          yMove: yMove,
          max: 100
        });
        this.count ++;
      }
    },
    draw: function (self) {
      var _this = self || this;
      var ctx = _this.ctx;
      ctx.clearRect(0, 0, _this.canvas.width, _this.canvas.height);
      _this.newDots = [_this.coordinate].concat(_this.dots);
      _this.dots.forEach(function (dot) {
        dot.xMove *= (dot.x > _this.canvas.width || dot.x < 0) ? -1 : 1;
        dot.yMove *= (dot.y > _this.canvas.height || dot.y < 0) ? -1 : 1;
        dot.x += dot.xMove;
        dot.y += dot.yMove;
        // 繪制點
        ctx.save();
        ctx.beginPath();
        ctx.arc(dot.x, dot.y, _this.size, 0, Math.PI * 5);
        ctx.fillStyle = _this.color;
        ctx.fill();
        ctx.restore();
        // 循環比對粒子間的距離
        for (var i = 0; i < _this.newDots.length; i ++) {
          var newDot = _this.newDots[i];
          // 如果是第一個點,則跳過
          if(newDot === dot || newDot.x === null || newDot.y === null) continue;
          var xDistance = dot.x - newDot.x;
          var yDistance = dot.y - newDot.y;
          var distance = Math.sqrt(Math.pow(xDistance, 2) + Math.pow(yDistance, 2));
          // 顏色深度
          var deep = 0;
          // 小于最小距離,則連線
          if (distance <= newDot.max) {
            // 附近的小球向鼠標位置移動
            if(newDot === _this.coordinate && distance > (newDot.max / 2)) {
              dot.x -= xDistance * 0.05;
              dot.y -= yDistance * 0.05;
            }
            // 距離越近---值越大---顏色越深
            deep = (newDot.max - distance) / newDot.max;
            // 畫線
            ctx.save();
            ctx.beginPath();
            ctx.lineWidth = deep / 2;
            var colorInfo = _this.colorCheck();
            ctx.strokeStyle = "rgba(" + colorInfo[0] + ", " + colorInfo[1] + ", " + colorInfo[2] + "," + (deep + 0.4) + ")";
            ctx.moveTo(dot.x, dot.y);
            ctx.lineTo(newDot.x, newDot.y);
            ctx.stroke();
            ctx.restore();
          }
        }
        // 將已經計算過的粒子刪除,減少遍歷的總數量
        _this.newDots.splice(_this.newDots.indexOf(dot), 1);
      });
      window.requestAnimationFrame(function (obj) {
        _this.draw(_this);
      });
    }
  }
  var moveBalls = new MoveBalls("#cs", {total: 66, color: "#00D0FF", size: 1});
</script>
</html>

藍藍設計www.0391cbd.com )是一家專注而深入的界面設計公司,為期望卓越的國內外企業提供卓越的UI界面設計、BS界面設計 、 cs界面設計 、 ipad界面設計 、 包裝設計 、 圖標定制 、 用戶體驗 、交互設計、 網站建設 平面設計服務


日歷

鏈接

個人資料

藍藍設計的小編 http://www.0391cbd.com

存檔

主站蜘蛛池模板: 国产黑丝视频在线观看| 华人在线亚洲欧美精品| 国产高清国内精品福利| 国产精品久久精品| 97久久人人超碰国产精品| 日韩在线永久免费播放| 欧美精品亚洲精品日韩专区| 国产av剧情无码精品色午夜| 亚欧成人无码AV在线播放| 波多野结衣久久精品| 在线欧美a| 国产免费久久精品99re不卡 | 都市激情亚洲综合久久| 久久黄色毛片| 九九免费观看全部免费视频| 欧美色图久久| 国产精品开放后亚洲| 国产三区二区| 亚洲天堂2014| 2020国产精品视频| 午夜a级毛片| 啪啪永久免费av| 欧美日韩动态图| 国产导航在线| 亚洲精品老司机| 亚洲国产无码有码| 性欧美久久| 黄网站欧美内射| 亚洲第一区精品日韩在线播放| 亚洲A∨无码精品午夜在线观看| 成人综合久久综合| 91美女视频在线| 日韩午夜片| 亚洲男人在线| 亚洲精品福利视频| 国产乱子伦无码精品小说| 免费在线a视频| 久久青青草原亚洲av无码| 国产第一页屁屁影院| 狠狠色噜噜狠狠狠狠色综合久| 久久公开视频| 久久精品人人做人人爽97| AⅤ色综合久久天堂AV色综合| 伊人福利视频| 色综合狠狠操| 亚洲bt欧美bt精品| 亚洲天堂成人| 波多野结衣中文字幕久久| 欧美色亚洲| 欧美a在线看| 日韩AV无码免费一二三区| 97se亚洲综合| 国产视频久久久久| 国产欧美日韩资源在线观看| 在线观看无码av五月花| 毛片在线看网站| 国产乱子伦视频在线播放| 日韩经典精品无码一区二区| 2020最新国产精品视频| av大片在线无码免费| 亚洲资源站av无码网址| 久久久久国产一级毛片高清板| 国产农村妇女精品一二区| 国产精品yjizz视频网一二区| 日韩免费无码人妻系列| 永久免费av网站可以直接看的| 日韩无码黄色网站| 欧美全免费aaaaaa特黄在线| 在线亚洲小视频| 国产午夜福利在线小视频| 91人人妻人人做人人爽男同| 色久综合在线| 四虎成人精品在永久免费| 在线观看91精品国产剧情免费| 无码 在线 在线| 色丁丁毛片在线观看| 思思热在线视频精品| 69国产精品视频免费| 国产va在线观看免费| 好紧太爽了视频免费无码| 丁香亚洲综合五月天婷婷| 久久国产精品电影|