zoukankan      html  css  js  c++  java
  • 星空的效果

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

    <head>
      <meta charset="utf-8">
      <meta http-equiv="X-UA-Compatible" content="chrome=1">
      <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
      <style>
        * {
          padding: 0;
          margin: 0;
          box-sizing: border-box;
        }
      </style>
    </head>

    <body>
    <canvas id="canvas" width="1400px" height="650px" style="background: black;"></canvas>



      <script type="text/javascript">
      var canvas=document.getElementById("canvas");
      var width=canvas.width;
      var height=canvas.height;
      var ctx=canvas.getContext("2d");


        function Yuan(ctx,x,y){
            this.ctx=ctx;
            this.x=x;
            this.y=y;
            this.speedX=Math.random()*8-4;
            this.speedY=Math.random()*8-4;
            this.jiaSu=0.0001;
            this.color="white";
            this.banjing=.1;
        }
        Yuan.prototype.draw=function(){
          this.ctx.beginPath();
          if(this.speedX<0){
            this.speedX-=this.jiaSu;
          }else{
            this.speedX+=this.jiaSu;
          }
          if(this.speedY<0){
            this.speedY-=this.jiaSu;
          }else{
            this.speedY+=this.jiaSu;
          }
          this.banjing+=0.01;
          this.x+=this.speedX;
          this.y+=this.speedY;
          this.ctx.fillStyle=this.color;
          this.ctx.arc(this.x,this.y,this.banjing,0,2*Math.PI);
          this.ctx.fill();
          this.ctx.closePath();
        }
        var arr=[]
        setInterval(function(){
          ctx.clearRect(0,0,width,height);
        var yuan= new Yuan(ctx,width/2,height/2);
        arr.push(yuan);
        
        arr.forEach(function(item){
            item.draw();
        })
        if(arr.length>500){
          arr.shift();
        }
        console.log(arr.length);
        },16)


       function createColor(){
         return "rgb("+Math.random()*200+","+Math.random()*200+","+Math.random()*200+")";
       }
     
      </script>
    </body>

    </html>
  • 相关阅读:
    CentOS6.3 编译安装LAMP(4):编译安装 PHP5.2.17
    CentOS6.3 编译安装LAMP(3):编译安装 MySQL5.5.25
    解决URL中包含“%2F”导致Apache地址重写mod_rewrite失效的问题
    Apache静态编译与动态编译详解
    Apache常用2种工作模式prefork和worker比较
    Apache 优化配置10条建议
    Apache prefork 模块指令分析
    PHP上传(单个)文件示例
    CentOS6.3 编译安装LAMP(2):编译安装 Apache2.2.25
    CentOS6.3 编译安装LAMP(1):准备工作
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/12186513.html
Copyright © 2011-2022 走看看