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="1000px" height="500px" 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=Math.random()*2-13;
              this.zhongli=0.2;
              this.banjing=6;
              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;
            if(this.speedY>0){

              this.banjing-=0.2
              if(this.banjing<1){
                this.banjing=1
              }
              this.speedY+=this.zhongli;
              this.y+=this.speedY
            }else{
              this.banjing+=0.2
              if(this.banjing>10){
                this.banjing=10
              }

              this.y+=this.speedY
            }
              
            
            
            this.draw()
          }
          var arr=[]
         setInterval(() => {
          ctx.clearRect(0,0,width,height)
         
          ctx.fillStyle="yellow";
         
          ctx.fillText("马爱丽生日快乐",width/2,30);
          ctx.font="30px Verdana";
          ctx.textAlign="center";
          var qiu= new Qiu(ctx,width/2,height-30);
        
          for(var i=0;i<arr.length;i++){
            arr[i].update()
          }
          arr.push(qiu);
          if(arr.length>100){
            arr.shift()
          }
          //console.log(arr.length)
         
         }, 15);
         function createColor(){
          return "rgb(255,255,0)";
           return "rgb("+Math.floor(Math.random()*200)+","+Math.floor(Math.random()*200)+","+Math.floor(Math.random()*200)+")";
         }
       
      </script>
    </body >

    </html>
  • 相关阅读:
    ABP dynamic API
    SQL语句 还原未知逻辑名称数据库
    SQL 还原数据库
    使用开源项目集锦
    webp性能测评
    js通过继承实现私有函数
    js组合继承和寄生组合式继承比较
    JS中循环绑定遇到的问题及解决方法
    JS学习之事件流
    OpenGL利用模板测试实现不规则裁剪
  • 原文地址:https://www.cnblogs.com/liuhao-web/p/12179702.html
Copyright © 2011-2022 走看看