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>
  • 相关阅读:
    13之容器资源需求、资源限制及Metricserver(Heapster)
    04K8S之pod控制器
    08K8S之k8s认证和serviceaccount
    07K8S之Statefulset控制器
    [Database] Mongodb 分片集群
    IIS 配置.svc的MIME映射
    当前标识(IIS APPPOOL\ASP.NET v4.0)没有对“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files”的写访问权限 解决方案
    Kubernetes Dashboard 安装
    存储服务 使用S3存储桶上传文件以及使用CLI来访问S3服务
    Django使用pdfkit生成PDF文件提供下载
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/12186513.html
Copyright © 2011-2022 走看看