乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Java實(shí)踐:使用JS實(shí)現(xiàn)簡(jiǎn)單噴泉效果

       好程序員IT 2019-07-09

      使用JS實(shí)現(xiàn)簡(jiǎn)單噴泉效果,最近,在教學(xué)生使用JS的基本操作,為了練習(xí)JS的基本作用,特地寫了一個(gè)噴泉效果,代碼如下:

      頁(yè)面代碼:

      <!DOCTYPE html>

      <html>

      <head>

      <meta charset="UTF-8">

      <title></title>

      <script src="js/particle.js" type="text/javascript" charset="utf-8"></script>

      <style type="text/css">

      body{

      margin: 0px;

      }

      </style>

      </head>

      <body>

      </body>

      </html>

      Particle.js代碼如下:

      window.onload = function(){

      // 創(chuàng)建一個(gè)畫布對(duì)象

      var canvas = document.createElement("canvas");

      // 設(shè)置大小和顏色

      canvas.width = window.innerWidth;

      canvas.height = window.innerHeight;

      canvas.style.backgroundColor = "#333333";

      // 將畫布放置到body里

      document.body.appendChild(canvas);

      // 得到畫筆

      var context = canvas.getContext("2d");

      // 定義一個(gè)存放所有粒子的數(shù)組

      var particles = [ ];

      // 調(diào)用顯示粒子

      showParticle();

      // 創(chuàng)建并顯示粒子的方法

      function showParticle(){

      // 循環(huán)操作

      setInterval(function(){

      // 清空畫布

      context.clearRect(0,0,canvas.width, canvas.height);

      // 創(chuàng)建粒子

      var p = new Particle(canvas.width * 0.5, canvas.height * 0.5);

      // 將粒子裝入存放粒子的數(shù)組

      particles.push(p);

      // 循環(huán)更新所有粒子的位置

      for (var i = 0;i<particles.length;i++) {

      // 更新位置

      particles[i].updateData();

      }

      }, 50);

      }

      function Particle(x, y){

      // 原坐標(biāo)

      this.x = x;

      this.y = y;

      // 初始出現(xiàn)的改變的y的值

      this.yVal = -5;

      // 改變的x的值

      this.xVal = Math.random() * 8 - 4;

      // 定義一個(gè)下降的重力加速度

      this.g = 0.1;

      // 更新位置

      this.updateData = function(){

      // X值的變化

      this.x = this.x + this.xVal;

      // Y值的變化

      this.y = this.y + this.yVal;

      // 每次改變Y值速度的變化

      this.yVal = this.yVal + this.g;

      // 生成一個(gè)隨機(jī)顏色

      context.fillStyle = "#" + Math.floor(Math.random() * 0xffffff).toString(16);

      // 將更新位置后的圓繪制出來(lái)

      this.draw();

      };

      // 繪圖的方法

      this.draw = function(){

      // 開(kāi)始畫圖

      context.beginPath();

      // 畫圓

      context.arc(this.x, this.y,5,0,Math.PI * 2, false);

      // 結(jié)束畫圖

      context.closePath();

      // 填充

      context.fill();

      };

      }

      };

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多