久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      HTML5實(shí)現(xiàn)下雪效果的實(shí)例代碼分享

      下雪實(shí)例

      知識(shí)點(diǎn):

      canvas畫布

      數(shù)組

      繪畫函數(shù)

      效果:

      HTML5實(shí)現(xiàn)下雪效果的實(shí)例代碼分享

      源碼:

      ——————————

      <!doctype html>  <html lang="en">   <head>    <meta charset="UTF-8">    <meta name="Generator" content="">    <meta name="Author" content="">    <meta name="Keywords" content="">    <meta name="Description" content="">    <title>下雪</title>    <style>  *{padding:0;margin:0}  html{overflow:hidden}    </style>   </head>   <body>  <canvas id="canvas" style="background:#111"></canvas>  <audio src="http://dx.sc.chinaz.com/Files/DownLoad/sound1/201210/2178.mp3" autoplay loop/>  <audio src="http://dx.sc.chinaz.com/Files/DownLoad/sound1/201205/1430.mp3" autoplay loop/>  <script type="text/javascript">  window.onload = function(){  //獲取畫布對(duì)象  var canvas = document.getElementById("canvas");  //獲取畫布的上下文  var context =canvas.getContext("2d");  //獲取瀏覽器屏幕的寬度和高度  var w = window.innerWidth;  var h = window.innerHeight;  //設(shè)置canvas的寬度和高度  canvas.width = w;  canvas.height = h;  //1:如何產(chǎn)生雪花,一個(gè)圓 ,arc(x,y,r,start,end)  //初始化雪花數(shù)量  var num = 200;  //雪花數(shù)組  var snows = [];  for(var i=0;i<num;i++){  //x,y圓心掉的坐標(biāo)位置,r代表圓的半徑,d每個(gè)圓的每個(gè)圓之間的間距,c代表的顏色  var r = randColor();  snows.push({  x:Math.random()*w,  y:Math.random()*h,  r:Math.random()*10,  d:Math.random()*num  });  };  //繪畫的函數(shù)  function draw(){  context.clearRect(0,0,w,h);  context.beginPath();  for(var i=0;i<num;i++){  var snow = snows[i];  context.fillStyle = "rgba(255,255,255,0.9)";  context.moveTo(snow.x,snow.y);  context.arc(snow.x,snow.y,snow.r,0,Math.PI*2);  }  context.fill();  //掉落  drop();  };  var angle = 0;  function drop()  {  angle += 0.01;  for(var i = 0; i < num; i++){  var p = snows[i];  //記住兩個(gè)公式:Math.sin(弧度)返回是一個(gè)0 1 -1 的數(shù)字  //math.cos(1 0 -1 ) 自由體,  p.y += Math.cos(angle+p.d) + 1 + p.r*0.625;  p.x += Math.sin(angle) * 8 ;  //如果雪花到了邊界,進(jìn)行邊界處理  if(p.x > w+5 || p.x < -5 || p.y > h){  if(i%4 > 0) {  snows[i] = {x: Math.random()*w, y: -10, r: p.r, d: p.d};  }else{  //控制方向  if(Math.sin(angle) > 0){  snows[i] = {x: -5, y: Math.random()*h, r: p.r, d: p.d};  }else{  snows[i] = {x: w+5, y: Math.random()*h, r: p.r, d: p.d};  }  }  }  }  };  //執(zhí)行和調(diào)用函數(shù)  draw();  setInterval(draw,10);  //隨機(jī)顏色  function randColor(){  var r = Math.floor(Math.random() * 256);  var g = Math.floor(Math.random() * 256);  var b = Math.floor(Math.random() * 256);  return "rgb("+r+","+g+","+b+")";  };  };  </script>   </body>  </html>

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)