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="1500px" height="900px" style="border:1px solid black;background:black"></canvas>

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

          function Qiu(ctx,x,y){
            this.ctx=ctx;
              this.x=x;
              this.y=y;
              this.speedX=Math.random()*4-2;
              this.speedY=-1;
              this.zhongli=0.1;
              this.banjing=5;
              this.color=createColor()
            this.draw()
          }
          Qiu.prototype.draw=function(){
            this.ctx.beginPath();
            this.ctx.fillStyle=this.color;
            this.ctx.arc(this.x,this.y,this.banjing,0,2*Math.PI,false);
            this.ctx.fill();
          }
          Qiu.prototype.update=function(){
            this.x+=this.speedX;

            this.speedY+=this.zhongli;
          

            this.y+=this.speedY

            this.banjing-=0.03;
            if(this.banjing<1){
              this.banjing=1
            }
           
              
            
            
            this.draw()
          }
          var arr=[]
          var img =new Image()
          img.src="./4.png"
          img.onload = function () {
         setInterval(() => {
          ctx.clearRect(0,0,width,height)
        
         
            ctx.drawImage(img,500,130,300,500);
              
          
        
          var qiu= new Qiu(ctx,width*Math.random(),0);
          var qiu1= new Qiu(ctx,width*Math.random(),0);
        
          for(var i=0;i<arr.length;i++){
            arr[i].update()
          }
          arr.push(qiu);
          arr.push(qiu1);
          if(arr.length>300){
            arr.shift()
          }
          //console.log(arr.length)
         
         }, 15);
        };
         function createColor(){
          return "white";
           return "rgb("+Math.floor(Math.random()*200)+","+Math.floor(Math.random()*200)+","+Math.floor(Math.random()*200)+")";
         }
       
      </script>
    </body >

    </html>
  • 相关阅读:
    CMU15-445 Project #2
    CMU15-445 Project #1 Buffer Pool
    挂分原因
    「杂谈」关于斜率优化维护凸包
    「题解」GYM 101620J Justified Jungle
    「题解」AGC 052 B Tree Edges XOR
    C++ MT19937 随机数 限制范围
    「题解」Codeforces 348C Subset Sums
    「学习笔记」联赛数论再学习
    「题解」洛谷 P4597 序列sequence
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/12179819.html
Copyright © 2011-2022 走看看