js实现canvas炫酷彩色流体转动动画效果代码

代码语言:html

所属分类:粒子

代码描述:js实现canvas炫酷彩色流体转动动画效果代码

代码标签: 炫酷 彩色 流体 转动 动画 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>



    <style>
        body {
          background: #111;
          overflow: hidden;
        }
        
        canvas {
          bottom: 0;
          left: 0;
          margin: auto;
          position: absolute;
          right: 0;
          top: 0;
        }
    </style>
</head>

<body>

    <div></div>

    <script>
        var $ = {};
        
        $.Particle = function( opt ) {
          this.radius = 7;
          this.x = opt.x;
          this.y = opt.y;
          this.angle = opt.angle;
          this.speed = opt.speed;
          this.accel = opt.accel;
          this.decay = 0.01;
          this.life = 1;
        };
        
        $.Particle.prototype.step = function( i ) {
          this.speed += this.accel;
          this.x += Math.cos( this.angle ) * this.speed;
          this.y += Math.sin( this.angle ) * this.speed;
          this.angle += $.PI / 64;
          this.accel *= 1.01;
          this.life -= this.decay;
          
          if( this.life <= 0 ) {
            $.particles.splice( i, 1 );
          }
        };
        
        $.Particle.prototype.draw = function( i ) {
        .........完整代码请登录后点击上方下载按钮下载查看

网友评论0